[英]modify / move an existing html tag in the DOM (javascript)
I want to move my div class="contentlinks" tag with its content, to place it in the div class="row" after the div class="col-12".我想移动我的 div class="contentlinks" 标签及其内容,将它放在 div class="col-12" 之后的 div class="row" 中。 Here is the basic html architecture:
这是基本的 html 架构:
<span id="data">
<section id="" class="thesectionQ">
<div class="container">
<div class="row">
<div class="col-12">
<h1>Title</h1>
</div>
</div>
</div>
</section>
<div class="col-12 contentlinks">
<a class="btn">link1</a><a class="btn">link2</a>
</div>
</span>
Tags are dynamically created in js... my problem is that I can't seem to use appendChild...标签是在js中动态创建的......我的问题是我似乎无法使用appendChild......
my problem is that I can't seem to use appendChild...我的问题是我似乎无法使用 appendChild ...
I'm trying to target my section with a class="thesectionQ" in a variable as well as my div class="contentlinks" that I want to move:我正在尝试使用变量中的 class="thesectionQ" 以及要移动的 div class="contentlinks" 来定位我的部分:
for example...例如...
var thedata2 = document.getElementById('data').getElementsByClassName('thesectionQ');
var thedata = document.getElementById('data').getElementsByClassName('contentlinks');
thedata2.appendChild(thedata);
but I have errors... and too often但我有错误......而且太频繁了
give section id so it become easy.给出部分ID,这样它就变得容易了。
document.querySelector('#sectionId div.row')
.appendChild(document.querySelector('div.contentlinks'))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.