[solved] Dynamic link generation

[solved] Dynamic link generation

Hello, all. There's a feature I want to implement, but don't really know how to code. The intention is to use jQuery to convert words with a certain class attribute into Wikipedia links.

An example to make things clearer:

PLAIN TEXT: There is a <span class="wiki">penguin</span> there.
EXPECTED RESULT: There is a <a href="http://en.wikipedia.org/wiki/Penguin">penguin</a> there.

Hence the code would have to grab the string of words inside the tag and place them inside a href with the first part of the link already attached to it. Doesn't seem too complicated, but I wasn't able to do it.

I have been trying to use the code below (created by Patrick Haney and improved by enraged) as a basis, but no deal. This code subistitutes words for code, but it searches for specific words.

If anybody knows a script like that, wants to help me modify the code below, or can quickly craft a script for me, I'd be very grateful.

$(document).ready(function() {var values =
new Array ("VALUE"");
var newValues = new Array("VALUE");
$.each(values, function(i) { $value = this; $("*:contains('" + $value + "')", document.body).contents() .each(function() { if (this.nodeType == 3) { var rEx = new RegExp($value, "g"); $(this).replaceWith(this.nodeValue.replace(rEx, newValues[i]));}});});});


Regards,

Edit: typo