3
I’m having trouble getting a new div before another or just add a div, but with Javascript.
Example:
I already have a DIV
<div class="primeira"></div>
I want to add one above it with Javascript, getting like this:
<div class="div-adicionada"></div>
<div class="primeira"></div>
Lucas, I ask you to read this topic that teaches how to create a question, helps increase the chances of getting useful answers, alias Welcome to Stackoverflow BR! http://answall.com/help/how-to-ask
– Gabriel Rodrigues
If you’re using jQuery, see if that help you.
– Francisco
You can understand very well what he wants...
– Felipe Duarte
@Andersoncarloswoss 'put a new DIV before another', obviously it is an 'insertBefore', I see no reason to close just ask for more information until it is his first question.
– Felipe Duarte
I would like a script that creates a new DIV above another
– Lucas Giovanni
@Andersoncarloswoss, this is very correct, I believe it has already been discussed, between closing and improving the question (even though my opinion is to comment). But in this particular one, what does it have to improve? It’s more than clear.
– Felipe Duarte
I think I can understand now
– Lucas Giovanni
The easiest way to achieve this is by using the insertAdjacentHTML method, thus: Document.getElementsByClassName("first")[0]. insertAdjacentHTML("beforebegin", "<div class='div-added'></div>"); The support is very good. I posted here until the topic is open to answers. Then I reset.
– Brunno Vianna