View Full Version : Get Element By Id Where X = Y
05-05-2006, 12:23 AM
Is there anyway to do something like:
document.getElementById('frank').where( id<5 )
document.getElementById('frank').where( id.indexOf('tom') )
I know there is no where fucntion, but that shows you the type of thing I want to do.
E4X supports a similar type of syntax:
doc..*.(@id < 5)
Would return an XMLList of all elements in the doc Document object with a numerical value of the id attribute less than 5.
E4X is only supported in Firefox for now, and isn't currently hooked up into the live DOM yet, but you could experiment easily enough (on a page with well-formed XHTML):
var doc = new XML((new XMLSerializer()).serializeToString(document.documentElement));
05-05-2006, 05:23 AM
document.getElementById('frank') will return a unique single reference point in the page so there is no need to have the ability to say where anything.
IDs must be unique references in a web page. If you want to give multiple tags the same reference value you need to use class instead.
If you do that then you can do a getElementsByTagName() and then loop through the entries returned to test the attributes you want.
05-05-2006, 02:36 PM
He wanted to have pattern matching on the id.
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.