Skip to main content
Stack Overflow
  1. About
  2. For Teams

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

JQuery split array elements

I am trying to get the ids from some li elements. But I'm not sure how to split the results in the array. So message_1 becomes 1, message_2 becomes 2 and so on.

<ul id="chat_viewport">
<li id="message_1">message</li>
<li id="message_2">message this and that</li>
<li id="message_3">3</li>
<li id="message_4">4</li>
<li id="message_5">5</li>
</ul>
<a href="#" class="test">TEST</a>​
$("a.test").click(function(e) {
e.preventDefault();
var idarray = $("#chat_viewport")
 .find("li") //Find the li in #chat_viewport
 .map(function() { return this.id; }) //Project Ids
 .get(); //ToArray
var biggest = Math.max.apply( null, idarray );
alert(idarray);
});​

I have an example here http://jsfiddle.net/T5x5d/

Answer*

Draft saved
Draft discarded
Cancel

lang-js

AltStyle によって変換されたページ (->オリジナル) /