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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With