0

how can i remove style tag inside html

i want remove complete style tag and css inside it i try this:

  html = html.replace(/<br>/g, ' ');
        console.log('0='+html);
        html2 = html.replace(/<div>/g, ' ');
        console.log('1='+html2);
        html2 = html2.replace(/&nbsp;/g, ' ');
        html2 = html2.replace(/(<([^>]+)>)/ig,"");

but this just remove style tag and don't remove css

my style code

habiat
  • 1,245
  • 3
  • 16
  • 22
  • 3
    why didn't you use `$('html style').remove()` ? – Rajaprabhu Aravindasamy Aug 10 '14 at 07:33
  • Solution above looks good to me – Scott Mitchell Aug 10 '14 at 07:34
  • If ever there was a time for this, it's now -> [ZA̡͊͠͝LGΌ ISͮ̂҉̯͈͕̹̘̱ TO͇̹̺ͅƝ̴ȳ̳ TH̘Ë͖́̉ ͠P̯͍̭O̚​N̐Y̡ H̸̡̪̯ͨ͊̽̅̾̎Ȩ̬̩̾͛ͪ̈́̀́͘ ̶̧̨̱̹̭̯ͧ̾ͬC̷̙̲̝͖ͭ̏ͥͮ͟Oͮ͏̮̪̝͍M̲̖͊̒ͪͩͬ̚̚͜Ȇ̴̟̟͙̞ͩ͌͝S̨̥̫͎̭ͯ̿̔̀ͅ](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags), that's horrible! – adeneo Aug 10 '14 at 07:35
  • i use FreeTextBox and get text with : var html = ftb.GetHtml(); how use $('html style').remove() – habiat Aug 10 '14 at 07:44

1 Answers1

2

You can use the jQuery .remove() method to remove any style tags from your page:

$('html').find('style').remove();

If the HTML is in a variable (html), use:

$('style', html).remove();
PeterKA
  • 24,158
  • 5
  • 26
  • 48