Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using jquery remove style tag from html page

Tags:

html

jquery

css

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

Thanks.

like image 571
krishna Avatar asked Jan 12 '23 01:01

krishna


2 Answers

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

});

reference .remove() and .detach()

like image 131
Rituraj ratan Avatar answered Jan 21 '23 16:01

Rituraj ratan


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();
like image 35
sroy Avatar answered Jan 21 '23 18:01

sroy