How to use jquery after () in javascript?

1

How do I make javascript the same equivalent function in jquery after?

I want to add one div right after another, so

<div id="div1"></div>
<div id="div2"></div> <!-- div 2 adicionada via javascript após a divi1 -->

In jquery I use this:

$('#div1').after('<div id="div2"></div>');

But I wanted it in javascript. Can someone help me?

    
asked by anonymous 27.10.2018 / 14:22

1 answer

2

In JavaScript:

const div = document.querySelector('#div1');
div.insertAdjacentHTML('beforeend', '<div id="div2"></div>');

This is a way. There are other ways too. You can see this and other forms here in the documentation. link

    
27.10.2018 / 14:41