Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

My code looks like this:

<ul id="ulList">
  <li class="listClass" id="id1"><a href="http://link1">Link 1</a></li>
  <li class="listClass" id="id2"><a href="http://link2">Link 2</a></li>
  <li class="listClass" id="id3"><a href="http://link3">Link 3</a></li>
</ul>

Now I like to get the following:

All links as an array

All ids of li as an array

Can someone help me please?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
502 views
Welcome To Ask or Share your Answers For Others

1 Answer

var ids = new Array();
var hrefs = new Array();
$('#ulList li').each(function(){
  ids.push($(this).attr('id'));
  hrefs.push($(this).find('a').attr('href'));
})

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...