javascript - best way to remove the span tags without removing the inner text -


i have created function hide , show fields problem labels text inside td label id applied such resolution_type_c_label. cant hide td because breaks table layout hide text innerwrap. best remove span tags without removing text when want show fields.

$(document).ready(function(){     hide();      function hide(){         if($('#status').val() != 'resolved') {              $('#resolution_type_c').hide();             $('#resolution_type_c_label').wrapinner('<span id="wrap1" style="display:none"></style>');              $('#resolution_sub_c_label').wrapinner('<span id="wrap2" style="display:none"></style>');             $('#resolution_sub_c').hide();              $('#resolution_label').wrapinner('<span id="wrap3" style="display:none"></style>');             $('#resolution').hide();         }         else {             $('#resolution_type_c').show();             $('#resolution_sub_c').show();             $('#resolution').show();         }      } */      $('#status').on('change', function() {         hide();     });  }); 

you can use .unwrap() , .wrap().

.unwrap() remove parents of set of matched elements dom, leaving matched elements in place.

.wrap() wraps html structure around each element in set of matched elements.

courtesy @spokey comments on post

$('span').contents().unwrap(); 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -