Is there a way to set a background image on an img tag that doesn't have an id in jquery?
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 h开发者_如何学运维ave an id?
So something like:
$(this.img).css("backgroundImage", "url(images/expand.png)");
$('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)')
Why are you setting the CSS instead of changing the src of the image? Try
$("img", this).attr("src", "images/expand.png");
Yes it is possible.You have a typo. backgroundImage
should be background-image
like this:
$(this.img).css("background-image", "url(images/expand.png)");
Sure..
$('h3 img').css(/* --- */);
Just don't use .img
because that is for a css class called "img".
Sure,
$(this).animate({'height':'toggle'},function(){$(this).find('img').attr('src','pathtoimage.png');})
精彩评论