开发者

How do I remove something I previously added with .after(content) in jQuery?

What I'm trying to do:

Take a nav item - when it's clicked, add a "<" out to the side of it. Then when something different is clicked, I'd like to remove the "<" that I just added, so the newly selected item is the only item with the "<" next to it.

Simplified code:

$('.sidebar a').click( function() {
    //-->here I need to clear it off of any other items which have it
    $(this).after(' <');
});

(Incidentally, I recognize that I could do something with css, but that won't work in this instance. Needs to b开发者_如何学Ce js.)


Here's the code

$('.sidebar a').click( function() {
    //Remove if there are any currently on the page
    $("#remove_later").remove(); 
    //Add to the link user just clicked onto
    $(this).after('<span id="remove_later"> &lt;</span>');
});

Here's the jsfiddle link http://jsfiddle.net/MHhp4/


what about

$('.sidebar a').click( function() {
    //-->here I need to clear it off of any other items which have it
    $(this).after('<span id="remove_later"> <</span>');
});

and remove it with

$("#remove_later").remove();

?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜