lets say i have fallowing html...
<li ><a href="#" id="UsersGuides" ">Users Guides</a></li>
<li ><a href="#" id="Application" ">Application</a></li>
i am adding and removing class by fallowing jquery function...
jQuery('selected').removeClass('selected');
if(!jQuery("#"+selectedAsset).parents('li').hasClass('selected')){
jQuery("#"+selectedAsset).parents('li').addClass('selected');
}
but at the same time i want to add an image at the end of anchor tag, and it should get removed at the same time when i am removing the selected class.i know i can use append method but how to remove it when class get removed, i couldn't not find out. out put should look like in this way...when i clicked on this link
<li class="selected"><a href="#" id="UsersGuides" ">Users Guides</a><img width="10" height="18" src="/search/images/refineSearch-selectedRight.gif" style="position: relative; left: 9px;"></li>
<li ><a href="#" id="Application" ">Application</a></li>
and when i clicked on second link it should like...
<li ><a href="#" id="UsersGuides" ">开发者_如何学运维;Users Guides</a></li>
<li class="selected"><a href="#" id="Application" ">Application</a><img width="10" height="18" src="/search/images/refineSearch-selectedRight.gif" style="position: relative; left: 9px;"></li>
how to do this in jquery? Thanks in advance!!!
jQuery('selected').removeClass('selected').find("img").remove();
.append()
will insert inside your selected tag. If you could guarantee that the last element was your anchor then it would work. if there was anything else after the anchor then it would fail. If you selected the anchor, then you would expect to use the .after()
method.
To remove an element, use the .remove()
method upon the selected image.
精彩评论