1.setAttribute jquery attr(attrName,value) 设置属性 为class设置
2.getAttribute jquery attr(attrName) 获取属性
3.removeAttribute jquery removeAttr(attrName) 移除属性
1.js <p id="p" class="one">hello world</p> <script> var p=document.getElementById("P"); p.onclick=function(){ this.setAttribute("style","display:none") } console.log(p.getAttribute("class")) console.log(p.removeAttribute("class")) </script>2.jquery <p id="p" class="one">hello world</p> <script> $("p").click(function(){ $("this").attr("id","good") console.log($(this).attr("id")) $(this).removeAttr("class") }) </script>
4.cssText 批量操作属性
5.length 获取长度
6.getPropertyValue() 获取style属性里面的值
7.item 方法接收一个整数作为参数值,返回该位置的css属性名
8.removeProperty() 移除style里面的值
9.setProperty() 改变style里面的值
<p id="test">hello world</p>
<script>
var test=document.getElementById("test")
test.style.cssText="color:pink;background:#333;font-size:14px;border:1px solid red";
console.log(test.style.getPropertyValue("color"))
console.log(test.style.item(0))
test.onclick=function(){
this.style.removeProperty("color")
this.style.setProperty("background-color","green")
}
</script>