I have this script
$(document).on("click", "#ocs", function(){
alert("ASdasd");
});
but on a unknown reasons, it trigger the click twice. I can surely use
$("#ocs").unbind().click(function(){
alert("ASdasd");
});
to make it not trigger twice but for my requirements I don't use
$("#ocs").unbind().click(function(){
so any ideas how to do unbind() or not to make trigger twice using
$(document).on("click", "selector", function(){
?
I have this script
$(document).on("click", "#ocs", function(){
alert("ASdasd");
});
but on a unknown reasons, it trigger the click twice. I can surely use
$("#ocs").unbind().click(function(){
alert("ASdasd");
});
to make it not trigger twice but for my requirements I don't use
$("#ocs").unbind().click(function(){
so any ideas how to do unbind() or not to make trigger twice using
$(document).on("click", "selector", function(){
?
Share Improve this question asked Aug 4, 2015 at 5:24 Juliver GalletoJuliver Galleto 9,05727 gold badges92 silver badges169 bronze badges 6- 1 Can you show some HTML? It should not be triggering twice in the first place – AmmarCSE Commented Aug 4, 2015 at 5:25
- Its a system, very heavy html. – Juliver Galleto Commented Aug 4, 2015 at 5:30
- 3 Well, its either the handler is attached twice, or you have two elements with the same id – AmmarCSE Commented Aug 4, 2015 at 5:31
-
Did you set that inside a JS function? E.g.
function store() { $(document).on("click", "#ocs", function(){ ... }) }
– Robin Carlo Catacutan Commented Aug 4, 2015 at 5:33 - @AmmarCSE: ill take not of that, ill check that attached twice and same id stuffs, thank you – Juliver Galleto Commented Aug 4, 2015 at 5:39
2 Answers
Reset to default 9you can use one
for that
$(document).one("click", "#ocs", function(){
alert("ASdasd");
});
You can do this way:
$('#abc').bind('click', function() {
$(this).unbind('click');
alert('Clicked and Unbind');
});
The bind does allow you to re-bind the click event later if needed.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745337374a4623167.html
评论列表(0条)