javascript - How to prepend only once in jQuery in a Wordpress environment -


i working in wordpress environment. inserted custom section using jquery show "treasure trove" icon people can click on it. icon prepended default "red chat icon" created through chat plugin.

this makes div created directly related "red chat icon". whenever open , close default chat icon treasure trove icon duplicates every time. how go making "treasure trove" icon not duplicate every time opened , closed?

example

jquery

    jquery(document).on("wplc_animation_done", function(e) {                      jquery( "#wp-live-chat-header" ).append( "<div class='wp-live-chat-extend'><h2>chat us!</h2></div>" );               jquery( "#wp-live-chat" ).prepend( "<a href='/exatactical/treasure-trove/'><div id='pbf-treasure-trove' class='pbf-treasure-trove-bg'></div></a>" ); // inserts icon             jquery( "#pbf-treasure-trove" ).append( "<div class='wp-live-chat-extend'><h2>treasure trove</h2></div>" ); }); 

css

.wp-live-chat-extend {    opacity: 0;    width: 72px;    height: 72px; }  .wp-live-chat-extend:hover{    padding-left: 90px;    opacity: 1; }  .wp-live-chat-extend h2 {    color: #fff!important;    font-size: 20px;    width: 200px;    margin-top: 20px; }  #pbf-treasure-trove {    margin-bottom: 15px;    background-image: url(/exatactical/wp-content/uploads/2017/08/iconretina.png);    background-size: cover; }  #pbf-treasure-trove:hover {    background-image: url(/exatactical/wp-content/uploads/2017/08/iconretina2.png);    background-size: cover; }  .pbf-treasure-trove-bg {    border-radius: 62px 62px;    background: #00adef;    width: 62px;    height: 62px; } 

you should able exploit jquery's .one() method.

jquery(document).on("wplc_animation_done", function(e) {     jquery( "#wp-live-chat-header" ).append( "<div class='wp-live-chat-extend'><h2>chat us!</h2></div>" );      jquery( "#pbf-treasure-trove" ).append( "<div class='wp-live-chat-extend'><h2>treasure trove</h2></div>" ); }).one("wplc_animation_done", function(e) {     jquery( "#wp-live-chat" ).prepend( "<a href='/exatactical/treasure-trove/'><div id='pbf-treasure-trove' class='pbf-treasure-trove-bg'></div></a>" ); // inserts icon }); 

if necessary, other 2 lines can shuffled .one() handler.


Comments

Popular posts from this blog

angular - DownloadURL return null in below code -

meteor - inserting data to database gives error "insert failed: Method '/texts/insert' not found" -