Reputation: 49384
I have the code:
<img id="myid" class="myclass" src="image1.png" />
What I need to do is:
if myid contains a class="myclass" then change src="image1.png" to src="image2.png"
How can I do that with JQuery?
Upvotes: 0
Views: 815
Reputation: 1977
var e = $("#myid");
var ans = e.hasClass("myclass");
if(ans){
e.attr("src","image2.png");
}
$("#debug").text(ans+", src"+ e.attr("src"));
working example http://jsbin.com/evipuz/edit#javascript,html,live
Upvotes: 1
Reputation: 6115
if ($('#myid').hasClass('myclass')){
$('#myid').attr('src','image2.png');
}
Upvotes: 3