2

What's the simplest way to tell if an attribute exists?

p = <abc name="foo" />;


js>p.@name.length()
1
js>p.@zebra.length()
0

I can use @attr.length() but was wondering if there is an isAttributePresent() or something.

NOTE: This is not in a browser, this is just a javascript interpreter based on core Mozilla Javascript 1.8 with E4X enabled.

Jason S
  • 184,598
  • 164
  • 608
  • 970

1 Answers1

4

You can use

'@name' in p

This will return true or false depending on existence of said attribute.

Gabriele Petrioli
  • 191,379
  • 34
  • 261
  • 317