javascript - Strip content of specific tags -


i can strip html correctly out of string doing this:

htmltotext = function(html){     return jquery(html).text(); }; 

but there cases html string containing styling like:

<style type="text/css"> .button:hover {     background-color: #6b6d71; } </style> 

the function strip <style> tags text end with
.button:hover { background-color: #6b6d71; }

i'll know if jquery able strip styles , how.

you can use .clone() , remove style tags using .remove().

var $foo = $('.foo'),     $fooclone = $foo.clone();  $fooclone.find('style').remove();  $('#output').text($fooclone.text()); 

here small demo: http://jsbin.com/lamasabapu/1/edit?html,css,js,output


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -