javascript、jqueryで要素を前に追加する方法 [javascript]
javascriptでuiの初めに追加する場合
var ul = window.document.getElementById('h-feed')
var li = window.document.createElement('li')
li.setAttribute('class', 'h-entry collection-item avatar')
li.style.backgroundColor = 'rgba(255, 255, 255, 0.6')
ul.insertBefore(li, ul.firstChild)
jqueryでulの初めに追加する場合
var ul = $(window.document.getElementById('h-feed'))
var li = $(window.document.createElement('li'))
li.attr({class: 'h-entry collection-item avatar'})
.css({"background-color": "rgba(255, 255, 255, 0.6"})
ul.prepend(li)
var ul = window.document.getElementById('h-feed')
var li = window.document.createElement('li')
li.setAttribute('class', 'h-entry collection-item avatar')
li.style.backgroundColor = 'rgba(255, 255, 255, 0.6')
ul.insertBefore(li, ul.firstChild)
jqueryでulの初めに追加する場合
var ul = $(window.document.getElementById('h-feed'))
var li = $(window.document.createElement('li'))
li.attr({class: 'h-entry collection-item avatar'})
.css({"background-color": "rgba(255, 255, 255, 0.6"})
ul.prepend(li)
タグ:jQuery