Removing text that was appended previously

Tom picture Tom · May 27, 2011 · Viewed 14.5k times · Source

I have a highlighting function using JQuery, that changes the css for the clicked <li> element in a menu. The function also prepends a pair of left brackets << to serve as pseudo arrows.

But how do I remove that << when I switch to the next <li> ?

$(".sdv-nrml").click(function(){

//remove old highlighted li 
$(".sdv-nrml").css({'background' : '#ffcc66' , 'color' : '#000000' , 'text-align' : 'right'});

//assign new css and prepend arrow
$(this).css({'background' : '#996600' , 'color' : '#ffff66' , 'text-align' : 'left'});
$(this).prepend("<< ");
});

Thanks

Answer

dtbarne picture dtbarne · May 27, 2011

I would include the << in a <span>:

$(this).prepend('<span class="prepended">&laquo; </span');

then to remove:

$(".prepended").remove();

Note: I used « instead of <<. I find it a little more appealing.