Parsing XFN data with Jquery, round 2

92 Views Asked by At

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 :-)

1

There are 1 best solutions below

2
jitter On BEST ANSWER

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_$]*