web123456

JS gets custom attribute data value

<body>
<div data-leaves="47" data-plant-height="2.4m"></div>
<script>
var tree = ("tree");
//getAttribute() value attribute
(("data-leaves"));
(("data-plant-height"));
//setAttribute() Assign attribute
("data-leaves","48");

//data-prefix attribute can be used to get values ​​in JS through dataset, which is more convenient
();
();
//Assignment
= "3m";
--;
//Add data attributes
= "100";
//Delete, set to null, or delete
= null;
delete ;

//jQuery's data method
var $tree = $('#tree');
($("plant-height"));
</script>
</body>