javascript - Find <style> tag by id or attribute -
i dynamically remove or disable <style>
tag
that looks this
<style type="text/css" id="cssx/portal/simple-sidebar.css" designtr="cssx/portal/simple-sidebar.css"> #wrapper { padding-left: 0; -webkit-transition: 0.5s ease; -moz-transition: 0.5s ease; -o-transition: 0.5s ease; transition: 0.5s ease; } #wrapper.toggled { padding-left: 250px; } #sidebar-wrapper { z-index: 1000; position: fixed; left: 250px; width: 0; height: 100%; margin-left: -250px; overflow-y: auto; background: #000; -webkit-transition: 0.5s ease; -moz-transition: 0.5s ease; -o-transition: 0.5s ease; transition: 0.5s ease; } </style>
if have id or own defined designtr property, can't seem disable or remove so:
var id = 'x'; var designtr = 'x'; document.getelementbyid(id).disabled = true; //doesn't work, throws error saying element null $('style[designtr="' + designtr + '"]').remove(); //doesn't work, although strangely no error thrown
i read somewhere html5 style tags can't have valid id attribute.
all want either remove or disable style tag, given unique id have in hand.
works charm:
document.getelementbyid('remove').onclick = function () { document.getelementbyid('styl').remove(); };
<div>some div content</div> <button id="remove">remove</button> <style id="styl">div{background-color: red}</style>
Comments
Post a Comment