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

186
Views
How do you style a data created in javascript?

I am not sure how you go about styling a data attribute made in javascript.

const createTask = () => {
    const id = createId()
    const task = elements.input.value;
    const date = elements.cal.value;

    if(!task && !date) return alert("Please fill in task and select date");
    if(!task) return alert("Please fill in task");
    if(!date) return alert("Please select date");

    const tasks = document.createElement("div");

    tasks.innerHTML = `
    <div class="task" date-id = "${id}">
        <div class="content">
            <input type ="checkbox" class="tick">
            <input type ="text" class = text id = "text" data-id="" readonly>${task}
            <label class = "due-date" for ="text">${date}</label>
            <input type ="date" class = date id = "date">
        </div>

        <div class = "actions">
            <button class="edit" data-id="${id}>Edit</button>
            <button class="delete" data-id="${id}>Delet</button>
        </div>
    </div>
    `

    elements.list.appendChild(tasks)
    return tasks
}

What I am trying to style is the data-id="${id} for the edit and delete button. I did style the class edit and delete in CSS

CSS:

.task .actions .edit {
    background-image: linear-gradient(to right, var(--pink), var(--purple));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.task .actions .edit 
{
  font-size: 0.8rem;
  margin-left: 3rem;
  margin-top: 1rem;
}

.task .actions .delete {
    color: crimson;
}

That data-id="${id} is preventing the buttons from appearing, but I need it there as it tracks with the list ID and it can delete or edit the list.

about 4 years ago · Santiago Gelvez
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!