Your div
variable is a string, not a DOM element object:
var div = '<div>top div</div>';
Strings don’t have an appendChild
method. Instead of creating a raw HTML string, create the div as a DOM element and append a text node, then append the input element:
var div = document.createElement('div'); div.appendChild(document.createTextNode('top div')); div.appendChild(element);
Related Posts:
- Edit webpage with javascript trick – how to “unedit”?
- Automatically pausing html5 video as the ‘next’ button is pressed (javascript/ jquery)
- Is it possible to write data to file using only JavaScript?
- Remove CSS class from element with JavaScript (no jQuery) [duplicate]
- Is it possible to write data to file using only JavaScript?
- How to make JavaScript execute after page load?
- Set cookie and get cookie with JavaScript
- Which is better: or
- Onclick javascript to make browser go back to previous page?
- How to make JavaScript execute after page load?
- Why is my Javascript not working?
- How can I get the values of data attributes in JavaScript code?
- Javascript: getElementById vs getElementsById (both works on different pages)
- mailto using javascript
- mailto using javascript
- Mailto using Javascript?
- How to change css property using javascript
- javascript close current window
- I am trying to make a simple toggle button in javascript
- How to call a JavaScript function within an HTML body
- How to save user input into a variable in HTML and JavaScript
- Hiding a button in Javascript
- Show/hide ‘div’ using JavaScript
- How to make JavaScript execute after page load?
- Get HTML code using JavaScript with a URL
- Calculate percentage Javascript
- How to display image with JavaScript?
- Resize image with javascript canvas (smoothly)
- JavaScript function onhover in
- Check if an element contains a class in JavaScript?
- Hide element by class in pure Javascript
- How to play a mp3 using Javascript? [duplicate]
- mailto using javascript
- Function not defined javascript
- How to submit a form with JavaScript by clicking a link?
- How to call a REST web service API from JavaScript?
- Check a radio button with javascript
- How can I change an element’s class with JavaScript?
- JavaScript: Get image dimensions
- Why write script type=”text/javascript” when the mime type is set by the server?
- How to select an input element by value using javascript?
- javascript window.location in new tab
- How to create a hidden in JavaScript?
- How do I programmatically set the value of a select box element using JavaScript?
- How can I capture the right-click event in JavaScript?
- How do I clear the content of a div using JavaScript?
- How to make a word underline in Markdown
- How to set a border for an HTML div tag
- iframe refuses to display
- Setting table column width
- How to animate GIFs in HTML document?
- How to create uppercase in pure HTML
- How to change text transparency in HTML/CSS?
- What does the shrink-to-fit viewport meta attribute do?
- What formats can be displayed with type=”application/x-shockwave-flash”
- Placing border inside of div and not on its edge
- bootstrap navbar not working correctly
- How to outline text in HTML / CSS
- Play videos with iframe in html
- Vue is not defined
- How do I install a custom font on an HTML site
- How can I make my footer center to the bottom of the page?
- Why is marquee deprecated and what is the best alternative?
- Refresh/reload the content in Div using jquery/ajax
- “AutoComplete=Off” not working on Google Chrome Browser
- Why would max-width not work on this?
- Making text background transparent but not text itself
- How to access Session variables and set them in javascript?
- HTML onchange (this.value)
- How to make my website fit any screen size?
- Display:inline not working
- How do I load an HTML page in a div using JavaScript?
- Bootstrap 3 Glyphicons CDN
- ReactJS – .JS vs .JSX
- single line comment in HTML
- Mail will not send in HTML
- Custom title widget / HTML encoding
- Add HTML Snippet only on specific pages
- Beautify WordPress HTML output without any plugins
- Minify HTML, CSS, JS with PHPWee?
- Add custom html to nav_menu
- Prevent WordPress from messing my HTML
- Most valid way for the URL html structure
- Strange iframes added in wordpress 4.1 localhost
- HTML tables in content areas
- Why does hitting enter in Visual Editor add instead of ?
- Echoing a variable comes out with lots of white space
- WP List Pages – Add Title Attributes to Anchors
- creating a static HTML/JS/PHP page
- Time Delay a URL Redirect for Specific Page
- Cascading dropdown select search based on Parent Page & Child Page
- WordPress cascading dropdown selection search based on Parent Page & Child Page
- Adding HTML Code to Replace Text in PHP
- Landing Page with HTML CSS JS and Images on wordpress
- Get html from custom route api
- Collapsible menu on post sidebar only expands and does not collapse
- PayPall Button Data Issue
- Include Information Text within Registration Page
- Why wordpress can’t display the bash command properly?
- Render HTML with wp_send_json