jQuery replace first string match

Posted by P4tient on Stack Overflow See other posts from Stack Overflow or by P4tient
Published on 2010-06-16T19:42:53Z Indexed on 2010/06/16 20:02 UTC
Read the original article Hit count: 235

Filed under:
|

I have an array, like
var acronyms = {
'NAS': 'Nunc ac sagittis',
'MTCP': 'Morbi tempor congue porta'
};

I need to find first match of each acronym and wrap around with tag via jQuery.
E.g.
<div id="wrap">NAS dui pellentesque pretium augue. MTCP pellentesque pretium augue. NAS ac ornare lectus MTCP nec.</div>

becomes
<div id="wrap"><acronym title="Nunc ac sagittis">NAS</acronym> dui pellentesque pretium augue. <acronym title="Morbi tempor congue porta">MTCP</acronym> pellentesque pretium augue. NAS ac ornare lectus MTCP nec.</div>

Thanks.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery