javascript - Jquery replace img class src attribute -
i hoping find out why following code not work:
<script type = "text/javascript" language = "javascript"> $(document).ready(function() { $("#myimg").attr("src", "image2.jpg"); }); </script> <div> <img class = "myimg" src = "image1.jpg" alt = "sample image" /> </div>
while block does:
<script type = "text/javascript" language = "javascript"> $(document).ready(function() { $("#myimg").attr("src", "image2.jpg"); }); </script> <div> <img id= "myimg" src = "image1.jpg" alt = "sample image" /> </div>
in html in first block need set id of img tag myimg:
<img id="myimg"> if you're going call $('#myimg')
you can change jquery call like:
$('.myimg')
Comments
Post a Comment