Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Aug 2002
    Location
    Oregon, United States of America
    Posts
    882
    Thanks
    1
    Thanked 9 Times in 9 Posts

    Get Element By Id Where X = Y

    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.

    THanks!
    If I'm postin here, I NEED YOUR HELP!!

  • #2
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    E4X supports a similar type of syntax:

    Code:
    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):
    Code:
    var doc = new XML((new XMLSerializer()).serializeToString(document.documentElement));

  • #3
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,459
    Thanks
    0
    Thanked 632 Times in 622 Posts
    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.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #4
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts
    He wanted to have pattern matching on the id.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •