1

I am trying to pass the values from the ul#ignorelist.userlist li > a into an array called arr. But i dont need the whole href, i just need the userID.

Something like this: 14301, 65958

HTML:

<ul class="userlist floatcontainer" id="ignorelist">
    <li id="user14301"><input checked="checked" id="usercheck_14301" name=
    "listbits[ignore][14301]" type="checkbox" value="14301"><a href=
    "member.php?u=14301">Frenchy</a><input name=
    "listbits[ignore_original][14301]" type="hidden" value="14301"></li>

    <li id="user65958"><input checked="checked" id="usercheck_65958" name=
    "listbits[ignore][65958]" type="checkbox" value="65958"><a href=
    "member.php?u=65958">GermanMan</a><input name=
    "listbits[ignore_original][65958]" type="hidden" value="65958"></li>
</ul>

Jquery:

var arr = $('ul#ignorelist.userlist li > a').map(function() {
return this;
}).toArray();

Jsfiddle: http://jsfiddle.net/7dWFN/13/

1 Answer 1

3

Try this, note that you don't need toArray, map method returns an array.

var arr = $('#ignorelist.userlist li').map(function() {
      return this.id.match(/\d+/g).join('')
      // or return this.id.replace('user', '')
}).get()

http://jsfiddle.net/6aP7W/

var names = $('#ignorelist.userlist li a').map(function() {
      return $(this).text()
}).get()
Sign up to request clarification or add additional context in comments.

2 Comments

also can you tell me how to get the string value into the array, eg: ["Frenchy", "GermanMAN"]
@SOLDIER-OF-FORTUNE I have updated the answer, for sake of performance, you can cache the objects. var $li = $('#ignorelist.userlist li') for first map $li.map().... second: $li.find('a').map()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.