Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get multiple CSS properties with jQuery

I know you can SET multiple css properties like so:

$('#element').css({property: value, property: value});

But how do I GET multiple properties with CSS? Is there any solution at all?

like image 658
Christian Engel Avatar asked Feb 13 '12 23:02

Christian Engel


2 Answers

jquery's css method (as of 1.9) says you can pass an array of property strings and it will return an object with key/value pairs.

eg:

$( elem ).css([ 'property1', 'property2', 'property3' ]);

http://api.jquery.com/css/

like image 101
bawwb Avatar answered Sep 21 '22 03:09

bawwb


Easiest way? Drop the jQuery.

var e = document.getElementById('element');
var css = e.currentStyle || getComputedStyle(e);
// now access things like css.color, css.backgroundImage, etc.
like image 27
Niet the Dark Absol Avatar answered Sep 21 '22 03:09

Niet the Dark Absol