jQuery :not() selector for class not working -


i have following html:

<ul>      <li>hello</li>           <li>world</li>     <li class="not_me">hi</li> </ul> 

and i'd texts inside list items array in 1 jquery call:

arr = $('li:not(.not_me)').map(function(el, i) {     return $(el).text(); }); 

expected result:

arr = ['hello', 'world']

actual result:

arr = ['hello', 'world', 'hi']

why :not() exclusion not working? writing quotes "not('.not_me')" gives same result.

here's jsfiddle showing problem: http://jsfiddle.net/cc8ft/683/

the :not operator working fine, there other issues in code.

you have swapped el , i parameters, element comes in i parameter , index comes in el parameter.

the result not array, it's jquery object contains array. use get method array out of object.

var arr = $('li:not(.not_me)').map(function(i, el) {   return $(el).text(); }).get(); 

demo: http://jsfiddle.net/p8us6/


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -