I am trying to get and array of text after using the text function, having a ul list like
<ul> <li>one <ul> <li>one one</li> <li>one two</li> </ul> </li> </ul>
then get something like
['one', 'one one', 'one two']
The jQuery function always returns a jQuery object (that is based on an array), even if there are no elements that matches the selector.
inArray() method we can easily verify if values are available in an array of objects. The jQuery. InArray() is a built-in jquery method, used to find a given value within an array. If the value is available it returns its index, and if value not exists then it returns -1.
var array = $('li').map(function(){ return $.trim($(this).text()); }).get();
http://api.jquery.com/map/
Demo Fiddle -->
http://jsfiddle.net/EC4yq/
Try this:
$("li").map(function(){ return this.innerText })
or this:
$("li").toArray().map(function(i){ return i.innerText })
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With