3

Consider code A and code B. They look identical but one is written by me. The other, copy pasted from W3. Code A (the one written by me) doesn't work but Code B does. Why is this? I've done a string match and it says it doesn't match but putting them ontop of each other in notepad (the code being one line already) reveals that its not different at all. Is there anything i'm doing wrong?

Code A:

$(document).ready(function(){
$(".sub").click(function(){
$(".sub").slideToggle("slow");
  });
​});

Code B:

$(document).ready(function(){
$(".sub").click(function(){
$(".sub").slideToggle("slow");
  });
});
Fabrício Matté
  • 69,329
  • 26
  • 129
  • 166
AccidentallyC
  • 92
  • 1
  • 8
  • They don't look identical - they **are** identical. The problem is somewhere else. Make sure you've included the jQuery lib correctly and the markup is the same. – Fabrício Matté Jul 08 '12 at 22:54
  • what is the difference between A and B? – Ram Jul 08 '12 at 22:55
  • If a string compare says they're different there may be some whitespace or non-printable character in yours, but if you re-type yours from scratch it should work. You don't really say so explicitly, but presumably everything else on your page is the same and you're just changing those four lines of code? – nnnnnn Jul 08 '12 at 22:57
  • Compare the hex codes of both bits of code. – Lee Taylor Jul 08 '12 at 22:58
  • Yes everything is the same only those four are changed. It does seem that there is a character but how did i get that? undefined - seems that there is an unprintable character somewhere @zetlen the editor i used was dreamweaver 8 – AccidentallyC Jul 08 '12 at 23:06

1 Answers1

4

Before the edit was done on the post, the curly bracket on the last line in Code A has a different type of character set than the curly bracket in Code B. You can see this when doing a diff compare.

Copy/Paste the original into Notepad++ and you'll see the difference as well.

Code A: ?});

Code B: });

EDIT
It looks like the 2 characters are the entity of ​ and }. Take a look at the SO Question: What's HTML character code 8203?

Community
  • 1
  • 1
Metro Smurf
  • 37,266
  • 20
  • 108
  • 140
  • Hmm... i see. But how in the world did i get that? Did dreamweaver 8 append that to what i was typing? – AccidentallyC Jul 08 '12 at 23:07
  • +1, the code actually has an unprintable character.. @AccidentallyC didn't you copypasta it from somewhere? Those web editors often do that. – Fabrício Matté Jul 08 '12 at 23:07
  • Well the one i copied worked. The one i typed didnt work. The only thing i can think of is dreamweave0r's encoding or something. Haha – AccidentallyC Jul 08 '12 at 23:12
  • Glad to help. Welcome to SO and if this is the correct answer, mark as correct. Cheers! ps - be sure to read the [FAQ](http://stackoverflow.com/faq) – Metro Smurf Jul 08 '12 at 23:24
  • @FabricioMatte ok thanks for the tip. Actually ive been looking for the mark as correct ever since but i dont know where to find it. But now that youve pointed me to it. thanks – AccidentallyC Jul 09 '12 at 01:25
  • And none of the people really answered my previous questions anyway haha – AccidentallyC Jul 09 '12 at 01:28