good_evening
good_evening

Reputation: 21749

Get current css file

We have css file. Let's say we change it with jquery like that $('body').css('color':'red');. Is it possible to retrieve current .css file? If not, how would you try to do that?

Upvotes: 1

Views: 714

Answers (2)

Bergi
Bergi

Reputation: 664433

jQuery will only change the style attribute/property of the node, your css file won't change.

Of course you can alter css files (Totally Pwn CSS with Javascript/MDN, or simpler with .cssText), but not genuinely with jQuery.

Upvotes: 0

Rusty Fausak
Rusty Fausak

Reputation: 7525

A CSS file is static - if you change an element's style with jQuery that changes the element in the DOM, but not in the loaded CSS files. If you are interested in getting the current CSS style for a given property of an element, you can use jQuery's css() method.

If you are interested in getting all styling for a given element, perhaps this answer will help: https://stackoverflow.com/a/5830517/449853

This answer discusses where jQuery's css() method gets it's information: https://stackoverflow.com/a/1020560/449853

Getting all current styles might involve looping through all elements in the DOM.

Upvotes: 3

Related Questions