61,112
社区成员
发帖
与我相关
我的任务
分享
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>reorder lines</title>
<style>
.post:nth-child(2n+1) {
color: red;
}
</style>
</head>
<body>
<div id="par">
<section class="post"> this is the 1st line code </section>
<section class="post"> this is the 2nd line code </section>
</div>
<script>
var p = document.getElementById('par');
var lines = p.getElementsByTagName('section');
p.insertBefore(lines[1], lines[0]);
</script>
</body>
</html>