Reputation: 152627
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>
Upvotes: 0
Views: 95
Reputation: 630349
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).
Upvotes: 8