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

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -