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

136
Views
How could I set the value of a div?

I know this is not standard but I want to set the value of a div, like this:

<div id="div" value="1">

document.getElementById('div').value = 2;

to use the value you have to use document.getElementById('div').getAttribute('value') but I cant find any way to set it. thanks in advance!

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

0

You can't set a value to a div. Instead you can try to add a data attribute, like this:

<div id="div" data-value="1">

And if you want to access the data-value from javascript, just use

elem.dataset.{data_attribute_name};, in this case: document.getElementById('div').dataset.value;

Note that you can set multiple data attributes to one element, making it much more versatile than using value.

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!