Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get *all* CSS attributes with jQuery

Tags:

Here's how you get one css attribute using jQuery:

$('someObject').css('attribute')

How do you get them all? (without specifying and preferably in the following format so it can be reapplied with jQuery later):

    cssObj = {         'overflow':'hidden',         'height':'100%',         'position':'absolute',     } 

Thanks!!

EDIT

The methods I'm trying to get are declared in a style sheet (they are not inline). Sorry for not specifying.

like image 508
Kyle Cureau Avatar asked Oct 19 '10 04:10

Kyle Cureau


People also ask

How do I get all the CSS properties of an element?

The CSS of an element can be obtained using the getComputedStyle element function in JavaScript. It returns a JavaScript object containing CSS properties and their values. This object is indexed and iterable over the property names. The getPropertyValue(property) is used to get the value of a property.

How can give multiple CSS properties in jQuery?

Apply multiple CSS properties using a single JQuery method CSS( {key1:val1, key2:val2....). You can apply as many properties as you like in a single call. Here you can pass key as property and val as its value as described above.

What is the use of CSS () method in jQuery?

jQuery css() Method The css() method sets or returns one or more style properties for the selected elements. When used to return properties: This method returns the specified CSS property value of the FIRST matched element.

Can we change CSS property value using JavaScript or jQuery?

You can change CSS using the jQuery css() method which is used for the purpose of getting or setting style properties of an element. Using this method you can apply multiple styles to an HTML all at once by manipulating CSS style properties.


1 Answers

See this live example using the jQuery attribute selector

$(document).ready(function() {     alert($("#stylediv").attr('style')); });​ 
like image 99
svk Avatar answered Nov 10 '22 03:11

svk