I have a div which has different values defined
<div class="scontent" scountry="en-GB" snumber="22000"></div>
In addition I have an external Javascript file which should use the data provided in the div above and output the info.
<script>document.write("22000en-GB"); </script>
Is it possible with plain Javascript to look for the div with class="scontent" and include the values of scountry and snumber into the Javascript code dynamically?
let element = document.getElementsByClassName('scontent')[0];
let scountry = element.getAttribute('scountry');
let snumber = element.getAttribute('snumber');
You can get all additional attributes inside dataset of any element
const ele = document.getElementsByClassName("scontent")[0].dataset;
const scountry = ele.scountry;
const snumber = ele.snumber;