SoFunction
Updated on 2025-02-28

Attr attributes and study notes in JQuery [must read]

Use html to store data-key directly, and the key must be all lowercase.

<div data-mydata="123"></div>
($("div").data("mydata"));
//output 123

2. Avoid using short horizontal lines in keys

<a  data-foo-bar-baz="fizz-buzz" href="#">fizz buzz!</a>
$('#bar').data().fooBarBaz; //works
$('#bar').data()['fooBarBaz']; //works
$('#bar').data()['foo-bar-baz']; //does not work

The above attr attribute and () study notes in JQuery [must read] are all the content I share with you. I hope you can give you a reference and I hope you can support me more.