[RESOLVED]How do I set numerous attributes for a control in one line with jquery.

How do I set the following with one line?

 d.css('position', 'relative');
	    d.css('left', 'auto');
	    d.css('top', 'auto');
	    d.css('border', 'none');

Hi,

Try

d.css({position:"relative",left:"auto",top:"auto",border:"none"});

Just check the documentation at http://api.jquery.com/css/#css-properties 

(not directly related but you can also chain calls if you want to call css and something else for the same control).

jQuery’s .css() function within jQuery supports passing in a single object which allows you to set one or more attributes within a single statement :

// Set your properties in a single object
d.css({'position':'relative','left':'auto','top':'auto','border':'none'});

Additionally, as with most jQuery functions, you could chain several statements together on the same object :

d.css('position', 'relative').css('left', 'auto').css('top', 'auto').css('border', 'none');

One final option would be to simply define a class with all of these specific properties and just add the class to your element as well :

.yourClass { position: relative; left: auto; top: auto; border: none; }

Rion, I always appreciate your help!

Leave a Reply