admin管理员组文章数量:1278947
I'm loading text from database but I'd like to remove html link code from it with JavaScript.
So lets say the textarea right now displays:
<a rel="nofollow" href="//questions/ask">//questions/ask</a> - good page
and I want it to display:
//questions/ask - good page
Is there something lightweight I could use that would work for multiple links in the same textarea?
I'm loading text from database but I'd like to remove html link code from it with JavaScript.
So lets say the textarea right now displays:
<a rel="nofollow" href="http://stackoverflow.//questions/ask">http://stackoverflow.//questions/ask</a> - good page
and I want it to display:
http://stackoverflow.//questions/ask - good page
Is there something lightweight I could use that would work for multiple links in the same textarea?
Share Improve this question edited May 17, 2013 at 22:02 Turadg 7,6912 gold badges50 silver badges49 bronze badges asked Jan 8, 2011 at 17:58 MatBanikMatBanik 26.9k40 gold badges118 silver badges178 bronze badges3 Answers
Reset to default 8Inspired by this answer, use the browser's HTML parsing abilities to get this done right.
function strip(html)
{
var tmp = document.createElement("DIV");
tmp.innerHTML = html;
return tmp.textContent||tmp.innerText;
}
jQuery('#textareaid').text(function(index, text){
return strip(text);
});
Here's the JSFiddle of it working: http://jsfiddle/Au95R/1/
(Edited to use cleaner JS)
You could use strip_tag()
like in PHP: http://phpjs/functions/strip_tags:535
textareacontent = strip_tags(textareacontent, "<b><i>"); // remove all HTML except <b> and <i>.
you can do this using regular expressions. here is a question on stack overflow itself and the answer explains it well
本文标签: jqueryHow to remove HTML tags from textarea with JavaScriptStack Overflow
版权声明:本文标题:jquery - How to remove HTML tags from textarea with JavaScript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741299900a2371033.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论