Using jQuery inside of an href tag
I'm trying to find a way to call a jQuery statement from within an <a> tag
in an href attribute. My code looks like this:
<a href="javascript:$('#myElement').addClass('test');">
When I click on this link the browser (Firefox) goes to a blank page with:
[object Object]
IMPORTANT: I am using a third-party plugin that generates the anchor tag
code so I don't have access to add the code into the onclick event for the
<a> tag. I would also prefer not to have to introduce a function as a
wrapper to the statement as we're using AJAX.
The funny thing is, this works:
<a href="javascript:alert('test');">
Is there a reason why jQuery statements don't work in an href attribute?
Is it the leading dollar sign causing issues? Is there a way to make it
work?
No comments:
Post a Comment