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

223
Views
¿Cómo puedo asignar una ID única al elemento innerhtml?

tengo esta funcion:

 function displayInputIntro() { var submitbutton = document.getElementById('submitbutton') var intro = document.getElementById('Intro') var introNewSection = document.getElementById('intro-row') introNewSection.innerHTML += '<div class="col-lg-5 mb-lg-0 mb-4" id="intro">'; submitbutton.style.display = '' }

Esta función displayInputIntro() se puede llamar varias veces, e insertará esta nueva sección en el cuerpo del HTML tantas veces como se decida hacerlo. El problema es que quiero agregar un identificador único, de modo que si tuviera que agregar algo como esto:

 introNewSection.innerHTML += '<div class="col-lg-5 mb-lg-0 mb-4" id="intro"><a href="javascript;;" onclick="deleteInputFunc()">Remove Input</a>';,

y haga clic en Remove Input , luego eliminaría la entrada, no todas.

He intentado algo como esto:

 var uniqueID = new Date() introNewSection.innerHTML += '<div class="col-lg-5 mb-lg-0 mb-4" id="' + uniqueID '"'><a href="javascript;;" onclick="deleteInputFunc()">Remove Input</a>';, and click on `Remove Input`, then it would delete the input, not all of them.

pero eso no funciona. ¿Cómo puedo hacer esto?

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

está pasando una cadena al código html, no a la variable JS real. Puede probar algo como esto que encontré en ¿Cómo puedo aplicar una variable como ID de elemento con JavaScript? :

 var id = new Date(); var html ='<li id="' + id + '">' + '<input type="image" id="' + id + '" src="images/subtract.png" onclick="javascript:deleteProduct(this.id)" href="#">' + id + '</li>';
about 4 years ago · Santiago Gelvez 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!