document.createElement

要素を生成。

element = document.createElement(tagName);

<style>
.creele div {margin:10px;padding:10px;}
#creele_div01    {border:dotted 1px red;}
#creele_div02    {border:dotted 1px blue;}
button    {margin-bottom: 1em;}
</style>

<script>
function func_creele(){
    var v_creele = document.createElement('div');
    v_creele.setAttribute ('id','creele_div01');
    v_creele.innerHTML = '上段';
    var id_creele_div02 = document.getElementById('creele_div02');
    var pare_id_creele_div02 = id_creele_div02.parentNode;
    pare_id_creele_div02.insertBefore(v_creele,id_creele_div02);
}
</script>

<div class="creele">
    <div id="creele_div02">下段</div>
    <button onclick="func_creele();">button</button><br/>
    ボタンを押すと要素が生成されます。
</div>

See the Pen EVPYYj by nosigcode (@nosig) on CodePen.

tagTimeLog Lite

Simple time tracking tool
Developed by Namu Works