tags:

views:

80

answers:

1

I used to use this script for jquery email obfuscation:

    $(".replaceAt").replaceWith("@");
  $(".obfuscate").each(function () {
        $(this).attr("href", "mailto:"+$(this).text());
    });

<a class="obfuscate">name<span class="replaceAt">-AT-</span>server.com</a>

But with jQuery 1.4.x, I now get this error:

uncaught exception: Syntax error, unrecognized expression: @

Looking this up on the net, it looks like jQuery thinks that the @ is a special character. I tried to "\@" it and a few other things with not luck. I'm not enough of a jQuery ninja to know how to fix this. Any ideas?

+5  A: 

So I dug around in the jQuery release notes, and it might be related to this bug which was fixed in the 1.4.2 release. At any rate, I can verify that your script works great in 1.4.2. Hope this helps.

Edit:

$(document).ready(function() {
  $(".replaceAt").replaceWith("@");
  $(".obfuscate").each(function () {
    $(this).attr("href", "mailto:"+$(this).text());
   });
});
Greg W
+1 for digging.
Boldewyn
Interesting.... I'm still getting the bug with 1.4.2http://soapboxdave.com/jquerytest.html(It worked fine with 1.3.x)
David
It seems odd that this would be the cause of your error, but I noticed you're not using any form of a document-ready function. Failure to do so causes your script to execute before the DOM is finished loading, which can lead to unexpected results. I'll edit an example into my answer.
Greg W
Thanks Greg, that really did the trick. And I'm a little embarrassed by the missing document-ready thing. Geesh. Appreciate it!
David