is there a way to make a every instance of a word automatically turn into a link?
so for instance, everytime I write "apple", it is automatically formatted to <a href="www.apple.com" class="whatever" target="_blank">apple</a>
I'm assuming i could use javascript or possibly jquery.
thanks!
very very simple example...
jQuery
html
demo
Here's a simple jQuery plugin that should do the trick. It will only select text nodes so that if you have an element with a class
apple
or idapple
it won't get replaced. Additionally, if you have a link<a href="#">apple</a>
it won't get replaced (might be a little more than you need, but I thought I'd post it anyway):Usage:
Working example: http://jsfiddle.net/andrewwhitaker/VmHjJ/
Note that this could become inefficient rather quickly due to the use of the
$("*")
selector. If possible, you should replace it with something more specific (or remove the.find("*").andSelf()
portion entirely and pass the plugin a more specific selector).