rebulid href tag from text with jquery -


i have dynamic html:

<div class="msg_body"> <p> text... |uri=http://www.somesite.co.il/|some link|euri| text |uri=http://www.somesite.co.il/|some link|euri| , text... </p> 

i need extract uri string , replace:

1. |uri= [<a href"] 2. | [>]  3. |euri| [</a>] 

so... need bee this:

<p>some text... <a href="http://www.somesite.co.il/" target="_blank"></a>some link</a> text <a href="http://www.somesite.co.il/" target="_blank">some link</a> , text...</p> 

i stack @ point:

$('.msg_body').find('p').text().replace('|uri=','<a href="'); 

how can in jquery?

you can use regex in following way:

$('div.msg_body').html($('div.msg_body').html().replace(/\|uri=([^\|]+)\|/g, '<a href="$1" _target="blank">')); $('div.msg_body').html($('div.msg_body').html().replace(/\|euri\|/g, '</a>')); 

here's example.

or if want little more concise (and cache jquery object) can shortened to:

var $msgbody = $('div.msg_body'); $msgbody.html($msgbody.html().replace(/\|uri=([^\|]+)\|/g, '<a href="$1">').replace(/\|euri\|/g, '</a>')); 

here's example.


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -