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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:58:09+00:00 2026-05-26T01:58:09+00:00

In javascript, we can create a new DOM element in the following ways… By

  • 0

In javascript, we can create a new DOM element in the following ways…

By using the createAttribute() + setAttributeNode() dom methods:

var input = document.createElement("input"),
    type = document.createAttribute("type");

type.nodeValue = "text";
input.setAttributeNode(type);
container.appendChild(input);

or by just setting the attributes directly:

var input = document.createElement("input");

input.type = "text";
container.appendChild(input);

The latter can end up being quite lot less code, even when there are only a couple attributes per element.

The question: has anyone run across any drawbacks of the latter method (setting attributes directly)?

I tested this on several browsers (the latest FF, IE, Safari, Opera, old IEs – even IE6 worked) and on a basic test (inserting a text input with type, name, and maxLength attributes) they all passed. Here’s the fiddle if anybody needs it.

  • 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-26T01:58:09+00:00Added an answer on May 26, 2026 at 1:58 am
    document.createAttribute
    document.createAttributeNS
    element.getAttributeNode
    element.getAttributeNodeNS
    ... and a lot of others
    

    will be deprecated in DOM4, so don’t use it, just set with setAttribute(“name”,”value”)

    http://www.w3.org/TR/dom/#element

    someinput.type is different
    basically is a shortcut for doing

    setAttribute("type","text");
    getAttribute("text");
    

    hope this helps!

    element._some_attribute_ is not available for all attributes, just some:
    element.dir
    element.lang
    element.id
    ...etc
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In javascript you can create a Date object from a string, like var mydate
In javascript you can easily create objects and Arrays like so: var aObject =
Can I create an event so I can execute some javascript whenever an element
Can I create something like an Internet Explorer accelerator using JavaScript on the client-side?
How can i create a cookie by using javascript just for end of the
Can I add an object of Elements inside another DOM element using grab or
A preface: I'm new to javascript and trying to create a web visualization using
I know we can create new properties in Javascript objects during runtime but could
Im trying to find out a good JavaScript library that can create a nice
Can I create a javascript variable and increment that variable when I press a

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.