Reputation: 107
I have an image within a header 3 tag and I have a jquery function that expands and collapses the table. I need to change the expand / collapse icon when the function is done, which I can do. My question is can I change the image that is within the h3 tag even if it doesn't have an id?
So something like:
$(this.img).css("backgroundImage", "url(images/expand.png)");
Upvotes: 1
Views: 291
Reputation: 10926
Sure,
$(this).animate({'height':'toggle'},function(){$(this).find('img').attr('src','pathtoimage.png');})
Upvotes: 0
Reputation: 14600
Sure..
$('h3 img').css(/* --- */);
Just don't use .img
because that is for a css class called "img".
Upvotes: 0
Reputation: 10592
Yes it is possible.You have a typo. backgroundImage
should be background-image
like this:
$(this.img).css("background-image", "url(images/expand.png)");
Upvotes: 0
Reputation: 7546
Why are you setting the CSS instead of changing the src of the image? Try
$("img", this).attr("src", "images/expand.png");
Upvotes: 0
Reputation: 2008
$('h3').find('img').attr('src', 'url(images/expand.png)')
Or since you have a reference within the toggle:
$(this).find('img').attr('src', 'url(images/expand.png)')
Upvotes: 1