I am getting some XML back from an AJAX call (no surprise) and I want to do something but only on certain nodes and something else on the rest. For example
<xml>
<node name="x">
</node>
<node name="x">
</node>
<node name="y">
</node>
<node name="z">
</node>
</xml>
I want all the nodes with name x to go to one table and I want all the others to go to another table.
Use an attribute filter, in particular the attributeEquals filter:
$("node[name='x']");
To select all the other nodes, use the attributeNotEquals filter:
$("node[name!='x']");
You can then apply jQuery manipulations to move these nodes elsewhere.
Note that XPath-style selectors where deprecated in version 1.2, and have been removed altogether in jQuery 1.3.
If you can influence what the server sends, you may want to switch to using JSON instead, you may find it easier to parse.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With