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

132
Views
Create a new property and get element id?

I want to create a new property and get id for elements (demo1, demo2, demo3).

id: this.id = How do I get the id from the elements here?

Element.prototype.myData = {
  id: '1', 
  name: 'Caesar',
  title: 'Imperator'
  var att = "{id:"+id+";name:"+name+";title:"+title+"}";
  document.getElementById(this.id).setAttribute("myAtt", att); // get id of element
  
};

alert(document.getElementById("demo1").myData.id = "129"); // alert 129

alert(document.getElementById("demo2").myData.id = "65"); // alert 65
alert(document.getElementById("demo2").myData.name = "Aleksandar"); // alert Aleksandar

alert(document.getElementById("demo3").myData.title); // alert Imperator
<div id="demo1"></div>
<div id="demo2"></div>
<div id="demo3"></div>

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

0

class CustomDiv extends HTMLDivElement {
    myData = {
       id: '',
       name: 'Caesar',
       title: 'Imperator'
    };
    constructor() {
        super();
    }

    connectedCallback() {
        this.myData.id = this.getAttribute('id');
    }
}

customElements.define('custom-div',CustomDiv , {extends: 'div'});


alert(document.getElementById("demo1").myData.id); // alert demo1

alert(document.getElementById("demo2").myData.name); // alert Cesar

alert(document.getElementById("demo3").myData.title); // alert Imperator
<div is="custom-div" id="demo1"></div>
<div is="custom-div" id="demo2"></div>
<div is="custom-div" id="demo3"></div>

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!