0

You guys already helped me on correctly parsing the REL attribute on A tags, but there are two XFN values that I'm not able to match: "co-worker" and "co-resident". The hyphen causes an error with jquery.

I tried this

xfn_co-worker = $("a[rel~='co-worker']").length;

and this

xfn_co-worker = $("a[rel~='co\-worker']").length;

In both cases the error "Uncaught ReferenceError: Invalid left-hand side in assignment" is returned. (Being these standard XFN values, I'm forces to use them)

Any idea is appreciated, as usual :-)

Charles
  • 50,943
  • 13
  • 104
  • 142
Omiod
  • 11,285
  • 11
  • 53
  • 59

1 Answers1

4

This isn't an error in you selector. The error lies in your variable name.

You can't use mathematical operators in the variable name. So the problem is your use of the - sign.

Try replacing

xfn_co-worker

with e.g

xfn_co_worker

And it should work alright

xfn_co_worker = $("a[rel~='co-worker']").length;

Note: Your variable name must match the following regex [a-zA-Z_$][0-9a-zA-Z_$]*

jitter
  • 53,475
  • 11
  • 111
  • 124
  • So my problem was on understanding the error message ... I'm so ashamed for posting such a question, I was too worried about the jQuery selector that wasn't paying attention to the JS basics... Thanks a lot. – Omiod Nov 29 '09 at 20:47
  • no problem. It happens to everyone that we cannot see the forest for the trees ;) – jitter Nov 29 '09 at 20:55