jquery - using .one() on multiple classes -
i have multiple divs same class name, once 1 clicked don't want function happen again if same class clicked again.
$('.js-item').one( "click", function() { console.log('clicked once'); // once if div same class clicked again });
is there way .one() happen once on classes? because @ moment applies once each time individual div class name clicked.
i need these divs have same class name.
you can call off()
on classes after executing logic:
$('.js-item').one("click", function() { console.log('clicked once'); // once if div same class clicked again $('.js-item').off('click'); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="js-item">click me!</div> <div class="js-item">click me!</div> <div class="js-item">click me!</div> <div class="js-item">click me!</div> <div class="js-item">click me!</div>
using method makes one()
redundant, can revert standard on()
if prefer.
Comments
Post a Comment