Replacing text with a link in jQuery
- by Eli
I'm trying to replace a small part of text in a large HTML document with my own element which I create on the fly.
The text may be a huge bulk of text, html, images, what-ever, and what I want is to find the first (or all) the position of a certain string, and replace it with an element that I create using $('< span').
Using simple text.replace('the string', $('< span')); doesn't do the trick (I'm left with [object Object] and not the actual < span that I want.
The reason I don't just inject direct HTML is because I want to retain all the binds that are related to the object I'm creating. and doing a replace with a custom ID, and then attaching binds to the ID after the HTML has been altered, seems a bit dirty.
Thanks for the help! :)