how do I use javascript to extract some data into a variable? [duplicate]

If you want to get the data to handle:

let span = document.getElementBy('btn-orange');
let mpnCode = div1.getAttribute('data-mpn-code');
let color = div1.getAttribute('data-color');
let initialized = div1.getAttribute('data-initialized');

or just use it directly. For example:

let span = document.getElementBy('btn-orange');
console.log(div1.getAttribute('data-mpn-code'));
console.log(div1.getAttribute('data-color'));
console.log(div1.getAttribute('data-initialized'));

//output:

7290108862140

#2695d8

true

Leave a Comment