user1876422 user1876422 - 1 year ago 50
Javascript Question

Execute javascript code in a href tags

I have a page with several (100+) entries like this:

<a href="javascript:removeFromCart(12302, 2);" class="remove">Remove</a>

Now I am looking for a jQuery snippet which can be run in the console and helps me to "click" all those "links" and execute the javascript function removeCart() with the respective parameters.

This does not work:


Any ideas?

Answer Source

You can’t use .click() here, because there is no event binding for the anchor. You need to manually execute the contents of the href attribute, and that can easilly be done using eval():

$('.remove').each(function() {