I’m curious why this code is invalid:
$.each( $("p") ).css("color", "green");
While this code works fine:
$.each($("p"), function() { $(this).css("color", "green") });
Is it not possible to chain elements with each?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Remove the wrapper:
If you want to use
$.each, specify a function as a second argument:The jQuery method automatically returns an instance of the collection, so chaining should still be possible.
Demo: http://jsfiddle.net/pC2Bj/
See also:
$().each()$.each