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 333463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:57:49+00:00 2026-05-12T09:57:49+00:00

I want to make a constructor function that creates a documentElement object. As an

  • 0

I want to make a constructor function that creates a documentElement object.

As an example, consider the new Audio() constructor – it creates a documentElement object, and if you pass it some variables it populates the new documentElement with attributes. It doesn’t insert it into the DOM, it simply creates the object.

So, the question is – what makes a documentElement different from a vanilla javascript object (of the {property: value} kind), and can you write constructors for them like you can for objects?

Edit:

What I’m toying with is re-creating the new Audio() constructor in browsers that don’t have it, using a quicktime or flash HTMLObjectElement in place of the HTMLAudioElement.

It’s ok with me that audio.constructor will refer to HTMLObjectElement, as the result of using new Audio() in browsers that support it, is that audio.constructor refers to HTMLAudioElement.

I’m not sure about the Audio.prototype. When I query console.log(Audio.prototype) in browsers with Audio support, they return nothing at all – not even an empty line in console.log – so that’s got me stumped. If I understand right, though, it doesn’t affect what I’m aiming to do.

The aim is to be able to code using the Audio constructor, and have the browser handle it natively or set up a plugin instance if it needs to.

  • 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-05-12T09:57:49+00:00Added an answer on May 12, 2026 at 9:57 am

    The document element is not a plain JavaScript object, is a DOM Element object, that implements the general DOM Core document interface.

    You can create documentElements by using document.implementation.createDocument (available from DOM Core Level 2):

    function createDocument() {
     var doc = document.implementation.createDocument('http://www.w3.org/1999/xhtml',
                                                          'html',  null),
         body = document.createElementNS('http://www.w3.org/1999/xhtml', 'body');  
    
      doc.documentElement.appendChild(body);  
      return doc;
    }
    

    Edit:

    Do you mean something like this?

    function ElementCreator(tagName, attributes){
        this.element = document.createElement(tagName);
    
        for (var i in attributes) {
          this.element[i] = attributes[i];
        }
      return this.element;
    }
    
    var anchor = new ElementCreator('a', { id: 'myLink', href:'http://google.com',
                                           innerHTML:'Link text' });
    document.body.appendChild(anchor);
    // <a id="myLink" href="http://google.com">Link text</a>
    

    However I don’t see too much advantage of using a constructor function for that.

    The element is returned from the constructor function, the object instance is lost, anchor.constructor in the above example refers to HTMLAnchorElement instead of ElementCreator, and for that the access to the ElementCreator.prototype is also lost.

    It would make more sense if the DOM Element instance is wrapped on a member, or just implement a simple function.

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

Sidebar

Ask A Question

Stats

  • Questions 211k
  • Answers 211k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Each commit is a logical unit of work. Unfortunately, that… May 12, 2026 at 10:11 pm
  • Editorial Team
    Editorial Team added an answer You should check out the sketches gem which let's you… May 12, 2026 at 10:11 pm
  • Editorial Team
    Editorial Team added an answer Just use:- string sql = @"select * from person where… May 12, 2026 at 10:11 pm

Related Questions

I have a Java program that runs many small simulations. It runs a genetic
I want my PHP extension to declare a class equivalent to the following PHP:
I have an auto pointer implementation: template <typename T, bool Arr = false> class
I figured out how to create a static method that is available everywhere, for

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.