JSLite - node properties


If you have any questions, you are welcome to communicate in these places, and you are welcome to join the JSLite.io organization team for joint development!

pluck

Get the attribute value of each element in the object collection.

$("#box").pluck("nodeName") //⇒ ["DIV"]
$("#box").pluck("nextElementSibling") //⇒ <div class="boxs">1234567890</div>
$("#box").pluck("children") //⇒ [HTMLCollection[4]]

attr

Read or set dom attributes.

$(".button").attr({"class":"","style":"background:red"}) //⇒ self 设置红色清空class
$(".button").attr("class","name")  //⇒ self 设置class替换之前的
$(".button").attr("class")  //⇒ string 获取class属性值

removeAttr

Moves the specified attribute of all elements in the current object collection.

$("#box").removeAttr("class") //⇒ self 移除class

prop

Read or set dom properties. It takes precedence over attr when reading attribute values ​​because these attribute values ​​will change due to user interaction, such as checked and selected.

<input class="taiyang" id="check1" type="checkbox" checked="checked">
<input class="yaotaiyang" id="check2" type="checkbox">
$("#check1").attr("checked"); //=> "checked"
$("#check1").prop("checked"); //=> "true"
$("#check2").attr("checked"); //=> "false"
$("#check2").prop("checked"); //=> "false"
$("input[type="checkbox"]").prop("type",function(index,oldvalue){
console.log(index+"|"+oldvalue);
});
//=> 0|checkbox
//=> 1|checkbox
$("input[type="checkbox"]").prop("className",function(index,oldvalue){
console.log(index+"|"+oldvalue);
});
//=> 0|taiyang
//=> 1|yaotaiyang

removeProp

Removes a property for the matching element in the collection. removeProp() method is used to delete the property set set by the .prop() method.

Note: Do not use this method to delete native properties (properties), such as checked, disabled, or selected. This will completely remove the attribute; once removed, it cannot be added to the element again. Use .prop() to set these properties to false instead.

<p id="n2" class="demo test" data-key="UUID" data_value="1235456465">CodePlayer</p>

var $n2 = $("#n2");
$n2.prop("prop_a", "CodePlayer");
$n2.prop("prop_b", { name: "CodePlayer", age: 20 } );

console.log($n2.prop("prop_a")) //⇒ CodePlayer
console.log($n2.prop("prop_b")) //⇒ Object {name: "CodePlayer", age: 20}

$n2.removeProp("data-key");
$n2.prop("data-key") //⇒ undefined
$n2.attr("data-key") //⇒ "UUID"