js
1.HTMLElement类型对象的属性方法
获取:div.id div.className img.src
设置:div.id = 'mydiv' a.href = 'http://www.baidu.com'
2.getAttribute() setAttribute() removeAttribute()低版本的ie不支持
获取:div.getAttribute('id') div.getAttribute('class') img.getAttribute('src')
设置:div.setAttribute('id', 'mydiv') div.setAttribute('class', 'box')
删除:div.removeAttribute('id') div.removeAttribute('class')
3.通过attributes属性(得到NameNodeMap)
获取:div.attributes['id'].nodeValue div.attributes['class'].nodeValue;
设置:div.attributed['class'].nodeValue = 'Box'
删除:div.attributes.removeNamedItem('class')
4.判断是否有attr属性
return div.hasAttribute('attr')
jquery
获取:$('div').attr('class')
设置:$('div').attr('class', 'box') $('div').attr({'class':'box', 'title': 'title1'})
删除:$('div').removeAttr('title')