4

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

Thanks.

1
  • 4
    $('style').remove() ; ? Commented Oct 28, 2013 at 5:32

6 Answers 6

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

});

reference .remove() and .detach()

Sign up to request clarification or add additional context in comments.

Comments

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();

Comments

0
$(document).ready(function(){

$('style').remove() ;

});

1 Comment

Is there any way to remoev specify style element tag,thanks for the answer
0

try remove try this

$('style').remove();

Comments

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.

Comments

-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();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.