javascript - Allow just one click in class JQUERY -


i have link load via ajax content.

my problem is, don't want remove text "load comments", want not allow more clicks in class.

<a href="javascript:;" class="showcomments" id="'.$idf.'">load comments</a> 

jquery

var progressajax = false; $(function() {      $(".showcomments").click(function(){                 if(progressajax) return;                    progressajax = true;      var element = $(this);     var id = element.attr("id");      progressajax = false;            alert("ok");            $(data).hide().prependto('.varload'+id).fadein(1000);          //$(element).remove();         $(element).removeattr("href");         $(element).removeclass('showcomments');     });      }); 

i want see ok first time. how can remove class?

$(element).removeclass('showcomments'); 

this not working...

http://jsfiddle.net/qsn1tuk1/

use jquery's one() function

$(".showcomments").one("click", function() { 

http://www.w3schools.com/jquery/event_one.asp

the one() method attaches 1 or more event handlers selected elements, , specifies function run when event occurs.

when using one() method, event handler function run once each element.


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo