<div>good</div>
1、首先获取元素:var divObj = document.getElementByTag("div")[0]
2、设置id属性:divObj.setAttribute("id","divId")
或者divObj.id='divId'
js给li加id的方法是:<script type="text/javascript">
var ul = document.getElementById("ul")
li = document.createElement("li")
txt = document.createTextNode("txt")
li.className = 'className'
li.id='id' //此处添加id
li.onclick = function() {alert('helo')}
li.appendChild(txt)
ul.appendChild(li)
</script>