Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery chaining

I don't think I'm correctly understanding jQuery chaining. I'm looping through an array and trying to add div elements to my wrapper CSS class with each div element having a class of 'click' and custom css top and left attributes, like this:

$('<div></div>').appendTo('.wrapper').addClass('click').css('top',click.y).css('left'.click.x);

But it fails to work as expected - it adds one div element, sets my .wrapper div's class to 'click' and then stops.

If I remove

.css('top',click.y).css('left'.click.x);

it works as expected - adding new div elements to the wrapper div.

How can i get this to work properly? Thanks

like image 963
CJD Avatar asked Feb 23 '11 17:02

CJD


1 Answers

Use a JSON object for .css.

.css({
   'left' : click.x,
   'top' : click.y
 });
like image 173
Daniel A. White Avatar answered Oct 13 '22 10:10

Daniel A. White