Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8992533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:58:37+00:00 2026-06-15T22:58:37+00:00

I am developing a function to find a particular element within another element identifier

  • 0

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 dom document and call from there by passing the ID of the father and son as parameters.

Is this possible?

Thanks for your time.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T22:58:38+00:00Added an answer on June 15, 2026 at 10:58 pm

    Not discussing the bosh with non-unique ids, I will answer your actual question:

    Is it possible to add a method to the DOM document?

    Yes, see How to extend the DOM with JS. But do not do it! The reasons are discussed very well in Kangax’ article What’s wrong with extending the DOM.

    The second method, was to add a method to the dom document and call from there by passing the ID of the father and son as parameters.

    You could do this, yes, and would not cause too much harm. I’d guess it works well in all browsers, as you won’t have garbage-collection problems etc. anyway with a static function.

    Yet I can’t see a good reason to do it. It sounds to me like abusing the document variable as a namespace, while any other global variable or namespace object would’ve done it as well. For not creating possible (future) collisions, a dedicated namespace would be a better choice.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am still developing this function, but here is what I am intending it
I am currently developing a function that is meant to execute dynamically created SQL
I'm developing web site that loads pages dynamically using the .load function. For example:
I'm developing a JERSEY RESTFUL web service which has a function that accept an
I'm developing a zend framework application that includes a simple email function. The development
I am currently developing a Lithium application and have come across a function that
I don't believe any similar existing questions answer this one. I am developing a
Is there any tool can measure execution time for each function call and find
I am just getting started developing my first Android app, and one function that
I'm developing a simple function that should build a sql condition based on optional

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.