jquery - on click of each li get the ids of all li with same class -


i have dom element below

<ul id="names">    <li id="aa" class="selected">aa</li>    <li id="bb">bb</li>    <li id="cc">cc</li>    <li id="dd">dd</li> </ul> 

when click on li element class "selected" added element. , on click of selected li class removed. every time click on li need create array li elements selected.

if aa , bb selected array should ["aa", "bb"] , when uselect bb , select cc should become ['aa','cc']. array should created on click of li , not on click of button.

how can query? in advance

assuming want array of ids element has class of selected, map elements' ids array jquery's map(), anytime need them:

var ids = $('#names .selected').map(function(){     return this.id; }).get(); 

jsfiddle


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -