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

Return to Question

added 616 characters in body
Source Link
Ciprian
  • 3.2k
  • 10
  • 68
  • 101

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/

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.

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

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/

Source Link
Ciprian
  • 3.2k
  • 10
  • 68
  • 101

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.

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

lang-js

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