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

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -