jQuery : render only URL and <a> tag -
i have asked question didn't correct answer asking again.if have text below in textarea:
this normal text www.google.com <a href='xyz.com'>this link</a> <h3>don't render h3 tag</h3> <small>don't render small tag</small> tag.<strong> don't render strong tag</strong>
..and when submit textarea , put above string inside div should render as:
this normal text www.google.com this link <h3>don't render h3 tag</h3>
<small>don't render small tag</small>
tag.<strong> don't render strong tag</strong>
i.e. just want render <a>
tag , url (i.e. if write www.google.com or http://www.google.com should show link google.com), any other html tag should is. how can that?
the problem if d0n't user can play html
tag while posting text in website
simply use .replacewith()
:
demo: http://jsfiddle.net/dirtyd77/pwhn3/
$(function(){ $('a').replacewith(function(){ return $(this).text(); }); });
edit: (2/6/2014)
you can apply same logic regardless of tag type.
either use:
// tag - mean 'h1', 'h3', 'small' // $('h1, h3, small') $(tag).replacewith(function(){ return $(this).text(); });
demo: http://jsfiddle.net/pwhn3/1/
$(function(){ $('body :not(a, h3)').replacewith(function(){ return $(this).text(); }); });
Comments
Post a Comment