I have a link. When some one clicks on that I want to check some conditions before letting it work. If it’s false the default action should be prevented.
$(".pager-next a.active").click(function(event) {
if (!a == 1) {
event.preventDefault();
}
});
The link should only work if a is equal to 1. Is the above code correct. a is set to 1 if a particular condition is met. The link should only work if the condition is met.
Assuming by ‘should only work if a is equal to 1‘ you mean the text of the
aelement is equal to 1, try this:You can amend
text()to use whichever attribute of the element is available to you in jQuery.UPDATE
In which case, the problem was simply that your equality operator was incorrect: