I am experimenting with Jetpack and I would like to parse all the years in a given html page and then wrap the year with a link to the Wiki page. I tried the code in jquery and there it works but now I am using it in Jetpack and it gives an error $(doc).replace is not a function. I am definitely new to Jquery / Jetpack so maybe I am missing something really easy but your help is much appreciated.

EDIT: I have tried the suggestions but I am still stuck. The weird thing is that this

JQuery function works:

(function($) {
    $.fn.clickUrl = function() {  
            var regexp = /([1-2][0-9][0-9][0-9])/gi;
            this.each(function() {
    return $(this);

and basically, I would like to 'port' this function to Jetpack.

This is the 'old' non-working port of my JQuery function to Jetpack:

    html: "Hyperlink Years",  
    width: 80,  
    onReady: function(widget){  
        var regexp = /([1-2][0-9][0-9][0-9])/gi;
        var doc = jetpack.tabs.focused.contentDocument;
            $(doc).each(function() {
                    $(doc).replace(regexp,'<a href=\"$1\">$1<\/a>'));
       return $(doc); 

Was it helpful?


I'm not familiar with jetpack, but your jquery seems to be quite messed up.

If "doc" is an HTML document, then doing $(doc).each() doesn't really make sense. It would only loop once, and "this" would be the same as doc.

Then later you are doing $(doc).replace(regexp, ...), but replace() is not a jquery function. You might have wanted to do .html().replace(regexp, ...); HOWEVER, I do not recommend doing this because it will not work - you will just end up replacing any numbers in the document, even if they are part of another URL or the HTML of the page.

For more information, refer to this question or google for jquery text nodes: Find text string using jQuery?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow