How to use this code as Unobtrusively? To keep content and Behaviour separate.
<a href="nojavascript.html" onclick="functionName(); return false;"
onkeypress="functionName(); return false;">Link text</a>
How to use this code as Unobtrusively? To keep content and Behaviour separate.
<a href="nojavascript.html" onclick="functionName(); return false;"
onkeypress="functionName(); return false;">Link text</a>
You could write it like this:
<a href="nojavascript.html">Link text</a>
Then use jQuery's .bind() like this:
$("a[href$='nojavascript.html']").bind("click keypress", function() {
functionName();
return false;
});
Or alternatively, give it a class like this:
<a class="noJS" href="nojavascript.html">Link text</a>
And use a .class selector like $("a.noJS") instead to be a bit cleaner (or, if it's unique, use an ID).