Sunday, May 12, 2024
 Popular · Latest · Hot · Upcoming
105
rated 0 times [  108] [ 3]  / answers: 1 / hits: 21635  / 9 Years ago, wed, july 29, 2015, 12:00:00

I trying to Execute given .click(function() only on first click, but it always Execute when click.



It's works when click .more-post-button it will add class loading to .main ul and show-more-post to .main li after that remove Class loading on setTimeout function 7 second.



JS:



$(.more-post-button).click(function () {

$('.main ul').addClass('loading');
$('.main li').addClass('show-more-post');
setTimeout(function(){
$('.main ul').removeClass('loading');
},7000);

});


My question is how to do this for only on first click, not every time click.

Thanks in advance.


More From » jquery

 Answers
13

Try:



$(.more-post-button).one(click, function () {

$('.main ul').addClass('loading');
$('.main li').addClass('show-more-post');
setTimeout(function(){
$('.main ul').removeClass('loading');
},7000);
});


http://api.jquery.com/one/



It'll handle it only once.


[#65623] Monday, July 27, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
harleyaleenag

Total Points: 678
Total Questions: 121
Total Answers: 105

Location: Papua New Guinea
Member since Thu, Jul 9, 2020
4 Years ago
harleyaleenag questions
Thu, May 5, 22, 00:00, 2 Years ago
Wed, Aug 19, 20, 00:00, 4 Years ago
;