You can use .insertBefore()
:
parentElement.insertBefore(newElement, parentElement.children[2]);
More Related Contents:
- JavaScript DOM: Find Element Index In Container
- How to pass arguments to addEventListener listener function?
- Remove all child elements of a DOM node in JavaScript
- Changing website favicon dynamically
- What is the difference between children and childNodes in JavaScript?
- How to append text to a “?
- Setting innerHTML vs. setting value with Javascript
- What is my script src URL?
- javascript access parent DOM across domains?
- How to add/remove a class in JavaScript?
- jQuery: how to change tag name?
- Why is the loop assigning a reference of the last index element to? [duplicate]
- Get the string representation of a DOM node
- How can I remove all CSS classes using jQuery/JavaScript?
- Count immediate child div elements using jQuery
- How to fill in form field, and submit, using javascript?
- Is it possible to use HTML’s .querySelector() to select by xlink attribute in an SVG?
- event.toElement in IE8 and Firefox?
- JavaScript moving element in the DOM
- Where are constructors such as, `new Image()` and `new Option()`, documented?
- How to append text to a div element?
- Why is setTimeout(fn, 0) sometimes useful?
- JQuery html() vs. innerHTML
- How do I capture a CTRL-S without jQuery or any other library?
- Get Cell Location
- Attaching events after DOM manipulation using JQuery ajax
- Fill user name and password in a webpage using VBA
- Can I add arbitrary properties to DOM objects?
- Is there any way to find an element in a documentFragment?
- In JavaScript, how can I replace text in an HTML page without affecting the tags?