How to add a div element with id attribute "model" to another div with class = "products__item-in" using js?
-
Hello. I have a
& lt; div id = "model_sku" & gt; 452843 & lt; / div & gt;
tag, it needs to be added inside this tag:
& lt; div class = "products__item-in" & gt; & lt; / div & gt;
using javascript. Can you do this with queryEllement?
I'll be very thankful.JavaScript Cora Taylor, Oct 8, 2020 -
And this can be done using queryEllement
Yes. queryEllement to select.products__item-in
. And https://developer.mozilla.org/en/docs/Web/ API / Elem ... to insert content. Alternatively, if the target tag is not empty:
https://developer.mozilla.org/en/docs/Web/API / Elem ...Aiden Maldonado -
$('#model_sku').append('<div class="products__item-in"></div>');
or
$('#model_sku').prepend('<div class="products__item-in"></div>');
or (no jQuery)
var div= document.createElement('div');
div.className= "products__item-in";
document.querySelector('#model_sku').append(div);Anonymous
2 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!