How do you create an element with JavaScript without its literal name being displayed on the page?
-
By "literal name" I mean, for example: [object HTMLDivElement]
-
Answer:
I'm not at all sure what you're doing that does show the toString on the page, but here's some plain-old-js you can use to insert a new <div> as a child of the <body>. ;(function() { var div = document.createElement( 'div' ); // here you might want to add a class or an id or some additional content document.body.appendChild( div ); })(); However, it's probably a better idea for you to use something like jQuery for DOM manipulation. With jQuery, it would be just be a matter of: $( document.body ).append( '<div></div>' );
Jacob Rothstein at Quora Visit the source
Other answers
It appears you're creating the element correctly, but then inserting into the page incorrectly, perhaps using innerHTML or innerText. Use element.appendChild(newElement) or similar methods instead.
Tom Robinson
Related Q & A:
- How to create an SlideShow in javascript?Best solution by Stack Overflow
- How to create dynamic function in javascript?Best solution by Stack Overflow
- How to dynamically create object properties from an array in Javascript?Best solution by nfriedly.com
- How can you create a different page in Wordpress?Best solution by WordPress
- How do i create a Yahoo web page?Best solution by iwebhostingplans.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.