Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save seantunwin/5765508 to your computer and use it in GitHub Desktop.

Select an option

Save seantunwin/5765508 to your computer and use it in GitHub Desktop.
Removing then adding CSS via locating <style> tags in the document using jQuery In this example we locate the first <style> tag and remove it while keeping reference to the content of it in a variable. When our checkbox is clicked we re-add the CSS style(s) to the docuemnt.
/*
* Removing then adding CSS via locating <style> tags in the document using jQuery
*
* In this example we locate the first <style> tag and remove it
* while keeping reference to the content of it in a variable.
*
* When our checkbox is clicked we re-add the CSS style(s) to the docuemnt.
*
*/
<script>
$(document).ready( function() {
var css = $('body style').eq(1);
var chbox = $('input[type="checkbox"]') css.remove();
chbox.prop('checked', false);
chbox.click(function(){
chbox.prop('checked') ? $('body').append(css) : css.remove();
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment