javascript - Apply function to current click and remove function for other click -


trying apply function adddiv() current clicked element , it's working fine, it's not removing function adddiv() on click. when click on text, adddiv() function applied div tag , added sample text, need apply adddiv() function on current clicked tag. can me?

here link: https://jsfiddle.net/a0l2jj1y/1/

html

<div>     tesing 1 </div> <div>     tesing 2 </div> <div>     tesing 3 </div> 

js

$(function(){      function adddiv(){      $('<div class="txt"/>').text('sample text added').appendto('.clicked');      }      $(document).on('click', function(event){         var clickedtag = event.target         event.stoppropagation();         $('.clicked').removeclass('clicked');          if($(clickedtag).text().length >= 1){             $(clickedtag).addclass('clicked');             adddiv();         } else {             // need remove adddiv();         }     }); }); 

try:

$(function(){    function adddiv(){    $('<div class="txt"/>').text('sample text added').appendto('.clicked');    }   $(document).on('click', function(event){   var clickedtag = event.target   event.stoppropagation();   $('.clicked').removeclass('clicked');    if($(clickedtag).text().length >= 1){   $(clickedtag).addclass('clicked');   adddiv();    } else {   $(clickedtag).unbind();   }    });   }); 

Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -