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

  • SEARCH
  • Home
  • 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 9077157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:16:32+00:00 2026-06-16T19:16:32+00:00

I am learning how to write object oriented javascript. I have a simple class

  • 0

I am learning how to write object oriented javascript. I have a simple class to create div elements, but when I test the code no new elements are created. Am I doing this correctly? I am using the following code:

function elementCreation(elementParent, elementId, elementText) {
    this.elementParent = document.getElementsByTagName(elementParent)[0];
    this.elementId = elementId;
    this.elementHtml = elementText;
    this.elementMake = function (type) {
        newElement = document.createElement(type);
        // add new element to the dom
        this.elementParent.appendChild(newElement);
    };
}

var newObject = new elementCreation('body', 'testdiv', 'some text here!!!');
newObject.elementMake('div');
  • 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-16T19:16:33+00:00Added an answer on June 16, 2026 at 7:16 pm

    Your code works perfectly, congratulations.

    You simply can’t see an empty div without styling.

    See here a demonstration with styling :

    div {
     width:100px;
     height:100px;
     background-color:red;   
    }​
    

    Note that if your construction parameters were intended for the construction of the child element, you have to put them to some use. For example :

    function elementCreation(elementParent, elementId, elementText) {
        this.elementParent = document.getElementsByTagName(elementParent)[0];
        this.elementId = elementId;
        this.elementHtml = elementText;
        this.elementMake = function (type) {
            newElement = document.createElement(type);
            // add new element to the dom
            this.elementParent.appendChild(newElement);
            newElement.innerHTML = elementText;
        };
    }
    

    Demonstration

    I won’t try to use the elementId parameter : if you define a function, it’s probably to call it more than once and an id can’t be used more than once in HTML.

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

Sidebar

Related Questions

I am learning how to write test cases using Rspec. I have a simple
I have started learning Java and I have 1 issue: I write a simple
I'm learning to code in Java. I want to write simple chat with gui.
To start off, I am still learning object oriented programming. Ok, I have a
I am learning C, mainly by K&R, but now I have found an Object
Hi I am learning to write test cases with Rspec in ruby and am
I trying to write a PowerShell script (learning at the same time). I have
I am designing an object-oriented programming language for the purpose of learning. The language
I'm learning to write a simple parser-combinator. I'm writing the rules from bottom up
I'm new at object oriented programming and we are studying on a Java project.

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.