Is it possible to connect a filter twice in jquery?

Why does this work, but the second example does not work?

The first one works.

function someFunk() { $('.listOne li').filter(':odd').css('background-color', '#FFFFFF'); $('.listOne li').filter(':even').css('background-color', '#F0F0F0'); }; 

The second one does not work.

 function someFunk() { $('.listOne li').filter(':odd').css('background-color', '#FFFFFF').filter(':even').css('background-color', '#F0F0F0'); }; 

Can I not bind .filter () in jquery?

+5
source share
1 answer

you can use .end() to return to the previous stack after the DOM navigation methods .:

 $('.listOne li').filter(':odd').css('background-color', '#FFFFFF') .end().filter(':even').css('background-color', '#F0F0F0'); 
+16
source

Source: https://habr.com/ru/post/1203969/


All Articles