Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get array of values use JQuery? [duplicate]

Tags:

arrays

jquery

Possible Duplicate:
How to get all of the IDs with jQuery?

How can i get array of values attribute ID inside "span id='enable'" if i use JQuery?

<span id='enable'>
<p id='105'>English</p>
<p id='250'>Spanish</p>
<p id='56'>German</p>
</span>
<span id='disable'>
<p id='38'>BlaBla</p>
<p id='46'>BlaBla2</p>
<p id='87'>BlaBla3</p>
</span>
like image 289
TITAN Avatar asked Mar 24 '12 11:03

TITAN


1 Answers

You can use Jquery's map function. This will return array of "English","Spanish" and "German".

var myArray = $('#enable p').map(function(){
   return $(this).text();
}).get();

For getting Id's list you can do this

var myArray = $('#enable p').map(function(){
       return this.id;
    }).get();

See jsfiddle http://jsfiddle.net/B3LuE/

like image 71
Chuck Norris Avatar answered Oct 11 '22 22:10

Chuck Norris