Reputation: 1744
hi I want to disable click after the user clicked on an element
the elements loaded after my script (elements built by javascript) and I can't use these code
$('.disableClick').click(
function (e) {
e.stopPropagation();
return false;
}
)
and I use these code to do work on the element by click
$('body').on('click','.disableClick',
function (e) {
if(!is_valid)
{
e.preventDefault();
e.stopPropagation();
return false;
}
}
);
I think disabling click codes like e.stopPropagation() don't support for
$('body').on('click') event
Upvotes: 1
Views: 1790
Reputation: 605
You need to use unbind I guess. Try
if(!is_valid){
$('selector').unbind("click")
}
Upvotes: 1
Reputation: 140
try this:
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script type="text/javascript">
$('body').on('click','.disableClick',
function (e) {
$(this).attr("disabled", true);
}
);
</script>
It works on body
as well as on document
both
Upvotes: 1