Click to See Complete Forum and Search --> : Selecting Page Elements


Vattic
05-25-2008, 02:57 AM
I have been using a method similar to the following to select elements:

var allTags, thisTag;
allTags = document.evaluate(
"//table[@name='stats']",
document,
null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
null);


Then using a for loop to loop through them. I have been told this isn't the best way to select elements but this is the way I know best.

The problem I am having is I want to know how to do the same but match multiple attribute values and also only select elements that do not have certain attributes.

So say I wanted to select a only the second table in the following code:


<table width="360" cellpadding="2">
</table>

<table width="360">
</table>

<table width="360" cellpadding="0">
</table>


So I want to select the table with a width of 360 which has no padding attribute.

Cheers in advance.

rpgfan3233
05-25-2008, 02:10 PM
The following should work, I believe:
//table[@width='360' and @cellpadding='']