John John - 1 year ago 82
CSS Question

jQuery remove appended text

I have a like function, where on default state it is on black color, and whenever the user clicks the like button it turns blue and a "Liked" text will appear besides the like icon

It is working, clicking liked will turn to blue, then clicking the like again will turn to black. The problem arises when i use the append function, when i liked it, "LikedLiked" is showing, it supposed to be 1 'Liked" only and whenever i clicked again the like button, it removes all the element including the like icon. What i want is, just to remove the text only.

here's my code

<div class="extra content">
<a class="likeicon">
<i class="fa fa-thumbs-o-up" aria-hidden="true" ></i>

my jQuery

if($(this).css("color") === "rgb(0, 0, 255)"){
$(this).css("color", "black");
} else {
$(this).css("color", "blue");

i've checked here on stackoverflow, i tried using .empty() and .remove() . but all of them get rids of my text and my like icon/

Thank you!

Answer Source

You can add text in elemrnt with id

 $(this).append("<span id="liked_txt">Liked</span>");

and when you want to remove it use

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download