Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

162
Views
Use div elements in Javascript file

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?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

let element = document.getElementsByClassName('scontent')[0];
let scountry = element.getAttribute('scountry');
let snumber = element.getAttribute('snumber');
about 4 years ago · Juan Pablo Isaza Report

0

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;
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!