简体   繁体   中英

Jquery: Select a href link and navigate with 'each' method

Is it possible using jQuery to select one full link that is in others 'tags'?

I would like select each href link of each item ( <li> )..

My idea is to use the method each and then extract the link, for use to navigate then.

This is the part of the code of the page: http://pastebin.com/3Vjib4UR

Where in full code of page, there more <li> items in the <ul> tag.

PS: I would like use the script in an external plugin of firefox (Greasemonkey),and not direct in the page.

Thanks in advance.

Kind regards.

Like this?

var arr = new Array();

$("a").each(function(){ arr.push($(this).attr("href"); });

Or shorter:

var links = $('a').map(function(){ return this.href;}).get();

If you want to get only certain links, just adjust the selector, eg

$('ul li a')

You really should learn how selectors works in order to use jQuery efficiently.

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