简体   繁体   中英

How can I convert this line of Jquery into pure Javascript?

How can I convert the Jquery code below into pure working JavaScript?

var newPage = $(this).data("page");

I've attempted the following code, but when I output it to the console I get undefined.

var newPage = this.dataset.page;

jQuery data() reads a jQuery-specific pool of data that is associated with the element.

That pool is initially populated with the values of data-* attributes, but then becomes independent.

If this.dataset.page is undefined then $(this).data("page") was probably initially set with jQuery and there's no reasonable way to access the data without first changing how it is set.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM