Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get stylesheet content from head

I am trying to get a certain stylesheet from the head using javascript/jQuery. I do not want to use $('head').get(0).innerHTML or similar cause the head is filled up with more than 30 script and link elements.

I tried this so far

// that's the one
var $my_stylesheet = $(document.body.previousSibling).find('link:last');

//those did not work (result: "")
$my_stylesheet.get(0).innerHTML;
$my_stylesheet.text();
$my_stylesheet.html();

What can i do to get the stylesheet content from the head?

like image 354
Thariama Avatar asked Nov 30 '22 07:11

Thariama


1 Answers

The actual way to access the stylesheets in Javascript is to reference document.styleSheets. If you have Chrome, or Firefox with Firebug, you can type that into the Javascript console and see what's available inside it.

Here are some good references to look at.

  • document.styleSheets - MDN
  • JavaScript Kit- DOM StyleSheet Object
like image 164
btleffler Avatar answered Dec 04 '22 10:12

btleffler