javascript - Automatically removing after append without binding -


i've created function apply notification badge element specify, when update badge, need remove last one.

if notification 2, when re-loads need remove 2 , replace 1.

javascript

 function checknotifications(parent, child, notificationparent){     $(notificationparent).remove(".right-bar-notification-badge");     var amount = $(parent+" "+child).length;     if(amount > 0){         $(notificationparent).css("position","relative");         $(notificationparent).append("<div class='right-bar-notification-badge'>"+amount+"</div>");     }  } 

i know element has bind before can removed, best way me this, without having click or interact element?

i want whenever call function, removes existing badge , replaces another, if there more 0 notifications.

thanks

i ended using method

javascript

 function checknotifications(parent, child, notificationparent){     $(notificationparent+' .notification-badge-wrapper').html("");     var amount = $(parent+" "+child).length;     if(amount > 0){         $(notificationparent).css("position","relative");         $(notificationparent).append("<div class='notification-badge-wrapper'><div class='right-bar-notification-badge'>"+amount+"</div></div>");     }  } 

appended wrapper around each time , emptied wrapper each time function ran. in doing this, if amount 0, never appended notification badge.


Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -