-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

4
  • 1
    What have you tried so far? Commented Jul 24, 2019 at 9:23
  • On which event you want to pass this code? Commented Jul 24, 2019 at 9:23
  • There is no specific event. The information is on a product page and I want to extract this numer into a variable so I can use it. Commented Jul 24, 2019 at 9:26
  • see this link for more details. But what is it's use. Commented Jul 24, 2019 at 9:27

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.