DOM插入元素-----插入到元素前面
插入元素的方法,注意的是:
list为child的时候才能够插入到元素中
var newChild = document.createElement('A');
newChild.appendChild(document.createTextNode('chorme'));
newChild.setAttribute('href', 'http://www.baidu.com');
var list =document.getElementById('msie');
list.insertBefore(newChild, list.lastChild);
var brChild = document.createElement('BR');
list.insertBefore(brChild, list.lastChild);
This is my HTML page. <br>
<div id='firefox' ></div>
<hr/>
<div>
<ul>
<li id='firefoxListItem' title="firefox">
<a href="#" title="get Firefox" id="firefox">Firefox 2.0</a>
</li>
<li>
<a href="#" title="getMicrsoft Inter" id='msie'>ie11</a>
</li>
<li>
<a href="#" title="check out safari" id='safari'>safari</a>
</li>
<li>
<a href="#" title="getOpera" id='Opera'>Opera</a>
</li>
</ul>
</div>
- Firefox 2.0
- chorme
ie11 - safari
- Opera