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/

or can use :not or .not():

$(function(){     $('body :not(a, h3)').replacewith(function(){         return $(this).text();     }); }); 

demo: http://jsfiddle.net/pwhn3/2/


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -