1

I am trying to accomplish something like this :

<?php $url = 'http://www.mydomain.com/img/picture.jpg'; ?>
<img src='<?php echo $url ?>' />

Only the problem is I want to accomplish this using javascript. Something like this

<script>url = 'http://www.mydomain.com/img/picture.jpg'</script>
<img src='<script>document.write(url)</script>' />

Of course it wouldn't work, but you got the idea. Any thought ?

2

2 Answers 2

5

Try - http://jsfiddle.net/m2Prh/

<img id="image" />​

<script>    
    var url = 'http://lorempixel.com/300/200';
    document.getElementById("image").src = url;​
</script>
Sign up to request clarification or add additional context in comments.

1 Comment

Very obvious simple solution. Never though of it. Thanks
0

I suggest reading jquery ,you can acesss every html element

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.