Strip Span Tags From String With Jquery
I am wanting to take the text value of a p tag when I press enter $.keynav.enterDown = function () { var accom = $('#suggestions p.keynavon').html(); alert(accom); } This is
Solution 1:
If you just want the text, which sounds like what you're after, use .text()
instead of .html()
, like this:
$.keynav.enterDown = function () {
var accom = $('#suggestions p.keynavon').text();
alert(accom);
}
If you actually need to strip the <span>
tags specifically, clone the content (as to not affect the original) and replace them with their inner content via .replaceWith()
, like this:
$.keynav.enterDown = function () {
var accom = $('#suggestions p.keynavon').clone()
.find('span').replaceWith(function() { returnthis.innerHTML; })
.end().html();
alert(accom);
}
Post a Comment for "Strip Span Tags From String With Jquery"