-3

HTML

<a href="/home/" id="one"><img src="images/img1.png"/></a> 

JS

<script>
$(document).ready(function(){
$('#one').

});
</script>

How to change anchor tag to <a href="/home/" id="one"><img src="images/img2.png"/></a> ?

SilentAssassin
  • 468
  • 1
  • 9
  • 27
SantaDev
  • 31
  • 1
  • 5

2 Answers2

1

Use the following code:

$("#one img").prop("src", "images/img2.png");

It will change the src property of <img> element to "images/img2.png".

VisioN
  • 143,310
  • 32
  • 282
  • 281
0

Try:

$(document).ready(function(){
    $('#one').on('click',function(e){
       $(this).children('img').attr('src','images/img2.png');
       e.preventDefault();
    });
});
Rohan Kumar
  • 40,431
  • 11
  • 76
  • 106