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?

David
  • 5,349
  • 1
  • 21
  • 15
  • Tested and working fine in 1.4.2. I'm curious, what encoding are you using? – Greg W Apr 14 '10 at 06:05
  • On second thought, I just tried it in 1.4.1 and I see the error you are getting. It looks like they must have fixed this in the .2 release. Try upgrading. – Greg W Apr 14 '10 at 06:08

1 Answers1

7

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
  • 5,219
  • 1
  • 27
  • 33
  • Interesting.... I'm still getting the bug with 1.4.2 http://soapboxdave.com/jquerytest.html (It worked fine with 1.3.x) – David Apr 15 '10 at 14:11
  • 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 Apr 16 '10 at 01:18
  • Thanks Greg, that really did the trick. And I'm a little embarrassed by the missing document-ready thing. Geesh. Appreciate it! – David Jul 13 '10 at 15:20