Reply to comment

Greetings:
I'm coming from a Mozilla/JavaScript 1.7 environment; so E4X is important for me as well. I have the same concern about using VARIABLES. I would like to know the correct synax for accessing ELEMENTS using a VARIABLE.

One classic need: to check for the existance of a particular ELEMENT using a VARIABLE that contains the ELEMENT's name.

After fiddling with your example and remembering about not using the '.' before the square brackets, I came across the following syntax:

var attr = "hairColor";
var val = "blond";
var creature = 'animal';
var x=...
var y = x[creature].(@[attr]==val).fav.color.@name);

Here, y = green.

Joel, you read my mind!
Great article!

Windows: "Where do you want to go today?"
Linux: "Where do you want to go tomorrow?"
FreeBSD: "Are you guys coming, or what?"

Reply

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Syntax highlight code surrounded by the {syntaxhighlighter OPTIONS}...{/syntaxhighlighter} tags.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters (without spaces) shown in the image.