gal007 Posted December 14, 2012 Share Posted December 14, 2012 (edited) I am developing a function to find a particular element within another element identifier (similar to getElementById but that applies to any other element) ... Because this throws me arror: var ancestor = document.getElementById('divAncestor');var child = ancestor.getElementById('divChild'); I know, HTML specifies that ids must be unique but reality proves that often running scripts that can have items with the same ids. So, thats the reason why I'm not simply calling the child like this: var ancestor = document.getElementById('divChild'); The first option was to add this function to each HTML element, or at least the divs (because that's what interests me identify). The second, and is the one I prefer, is to add a method to the document object and call from there by passing the ID of the father and son as parameters. Is this possible?Thanks for your time. Edited December 14, 2012 by gal007 Link to comment Share on other sites More sharing options...
justsomeguy Posted December 14, 2012 Share Posted December 14, 2012 It's probably possible, but it's never required or a good idea to have multiple elements with the same ID. If you think you need that, then your design isn't good. You never need multiple elements with the same ID, there is always a way around that. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now