UserSN
UserSN

Reputation: 1013

Using JQuery within an HREF link

I'm trying to use the following action which works fine in console but i'd like to have it fire when a link is clicked.

Code:

$('#angrid656 > div.angrid > div:nth-child(2) > div > table > tbody > tr:nth-child(1) > td.angrid-item-buttons.ng-scope > a.btn.btn-info.btn-accent.opacity75').click()

I've created the link like this but it's not working properly:

<a href="$('#angrid656 > div.angrid > div:nth-child(2) > div > table > tbody > tr:nth-child(1) > td.angrid-item-buttons.ng-scope > a.btn.btn-info.btn-accent.opacity75').click()"><div class="title">[Title]</div></a>

Upvotes: 0

Views: 53

Answers (1)

Barmar
Barmar

Reputation: 780713

If you want to execute Javascript in an href attribute, you have to begin with javascript:

<a href="javascript:$('#angrid656 > div.angrid > div:nth-child(2) > div > table > tbody > tr:nth-child(1) > td.angrid-item-buttons.ng-scope > a.btn.btn-info.btn-accent.opacity75').click()">...</a>

It doesn't matter whether it's plain Javascript or jQuery (which is just a library of Javascript functions).

You can also use an onclick attribute, and use href="#" to prevent the link from going anywhere automatically.

Upvotes: 1

Related Questions