简体   繁体   中英

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>

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM