I have a link:
Link
using::
$('#myID').click(function(){
if($("#myCheckbox").is(":checked")) {
alert('Yes it is...'); //continue as normal
}
else {
alert('Not checked');
//exit do not follow the link
}
...
so is //exit do not follow the link possible?
Description: The basic disable link is using removeAttr( 'href' ) to disable the href link. The “jquery disable link” is the button to be used for deactivating the web link.
To disable href if onclick is executed with JavaScript, we call preventDefault to stop the default navigation action. document. getElementsById("ignore-click"). addEventListener("click", (event) => { event.
One way you can prevent navigation is to implement an click / onclick JavaScript event handler and return false from it. Alternately you can use event. preventDefault() inside the click event's event object passed into the handler too.
To disable the click event on an element, we can use the pointer-events property. Simply set the pointer-events property to none to disable the click event on any element that you want. In the following example, we have disabled the click event for a button by simply setting its pointer-events property to none .
Try using event.preventDefault()
$('#myID').click(function(e) {
if ($("#myCheckbox").is(":checked")) {
alert('Yes it is...');
}
else {
alert('Not checked');
e.preventDefault(); // this prevents the standard link behaviour
}
}
Simple:
$('#myID').click(function (e) {
...
} else {
alert('Not checked');
e.preventDefault();
}
You can also use return false
, but this will also stop the propagation of the click event (which might be undesired).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With