-6

I need to extract some data

<span class="btn btn-orange" 
      style="visibility: visible; cursor: pointer;" 
      onclick="javascript:showPixelId(250);" 
      data-mpn-code="7290108862140" 
      data-color="#2695d8" 
      data-initialized="true">Acquista Online</span>

I have this code and I want the 7290108862140 to be returned into a javascript variable

adiga
  • 34,372
  • 9
  • 61
  • 83

1 Answers1

0

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

AndyNope
  • 427
  • 6
  • 12