Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery each element

Tags:

jquery

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?

like image 614
Ryre Avatar asked Jan 25 '12 20:01

Ryre


1 Answers

Note that no version of each is needed to achieve the (most likely) desired effect.

$("p").css("color", "green");

does the job.

like image 128
MaxH Avatar answered Oct 21 '22 03:10

MaxH