4

Is there any way to remove a <style> tag from the page using jquery? and i need to remove particular style tag.

Thanks.

krishna
  • 83
  • 2
  • 3
  • 11

6 Answers6

7
$(document).ready(function(){
    $('style').detach();
//        or
 $('style').remove();

});

reference .remove() and .detach()

Rituraj ratan
  • 10,260
  • 8
  • 34
  • 55
3

If you want to remove a specific style tag, you can add a class (or id) to it and then use remove() to remove that class. I have tested it and it works. I am not sure this should be allowed, but if you have no other options...

HTML

<style class="style-tag">
    p {
       color: #000;
    }
</style>

JQuery

$('.style-tag').remove();
sroy
  • 811
  • 7
  • 9
0
$(document).ready(function(){

$('style').remove() ;

});
underscore
  • 6,495
  • 6
  • 39
  • 78
0

try remove try this

$('style').remove();
bipen
  • 36,319
  • 9
  • 49
  • 62
0

To remove a particular style tag, you'd need to assign it an id, like this:

<style id="someid">.elem{display:none;}</style>

After that use jQuery's remove function to get rid of it, like this:

$('style#someid').remove();

I hope this helps.

Aamir Siddique
  • 334
  • 3
  • 15
-1

If you want to remove style tag from specific class or id ,then you can just mention their class or id name. Like this:

html:

<style>
.menu { display: none; }
</style>

jquery:

$('.menu style').remove();
Joke_Sense10
  • 5,341
  • 2
  • 18
  • 22