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

147
Views
Cómo agregar una clase html en la función javascript

Estoy tratando de crear una función que agregue un usuario en javascript.

Aquí están mis fragmentos de código del archivo js y el archivo html:

 function input() { document.getElementById("name").style.visibility = "visible"; document.getElementById("id").style.visibility = "visible"; document.getElementById("number").style.visibility = "visible"; document.getElementById("search").style.visibility = "visible"; } function addUser(list) { var text = ""; var inputs = document.querySelectorAll("input[type=text]"); for (var i = 0; i < inputs.length; i++) { text += inputs[i].value; } var list = document.createElement("div"); var node = document.createTextNode(text); list.appendChild(node); document.getElementById("usersList").appendChild(list); }
 <!DOCTYPE html> <html lang="en"> <head> <link rel="stylesheet" href="./style.css"> </head> <body> <div class="contact-container"> <div class="navbar"> <ul id="menuList"> <li> <img src="https://img.icons8.com/ios-filled/50/000000/contact-card.png"/> </li> <li>View</li> <li onclick="input()"> Add </li> </ul> </div> <div class="users"> <input type="text" id="name" placeholder="Name"/> <input type="text" id="id" placeholder="Id"/> <input type="text" id="number" placeholder="Number"/> <button type="submit" id="search" onclick="addUser()"> <svg...> </svg> </button> <div id="usersList"></div> </div> </div> </body> </html>
¿Cómo puedo hacer un estilo cuando agrego un usuario como el que tenía en el archivo html?

Aquí está mi proyecto:

ingrese la descripción de la imagen aquí

¡¡¡¡¡¡Muchas gracias!!!!!!

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

0

Coloque saltos de línea entre cada valor de las entradas y establezca el estilo del DIV en white-space: pre .

 function input() { document.getElementById("name").style.visibility = "visible"; document.getElementById("id").style.visibility = "visible"; document.getElementById("number").style.visibility = "visible"; document.getElementById("search").style.visibility = "visible"; } function addUser(list) { var text = ""; var inputs = document.querySelectorAll("input[type=text]"); for (var i = 0; i < inputs.length; i++) { text += inputs[i].value + '\n'; } var list = document.createElement("div"); var node = document.createTextNode(text); list.appendChild(node); document.getElementById("usersList").appendChild(list); }
 #usersList div { white-space: pre; }
 <!DOCTYPE html> <html lang="en"> <head> <link rel="stylesheet" href="./style.css"> </head> <body> <div class="contact-container"> <div class="navbar"> <ul id="menuList"> <li> <img src="https://img.icons8.com/ios-filled/50/000000/contact-card.png"/> </li> <li>View</li> <li onclick="input()"> Add </li> </ul> </div> <div class="users"> <input type="text" id="name" placeholder="Name"/> <input type="text" id="id" placeholder="Id"/> <input type="text" id="number" placeholder="Number"/> <button type="submit" id="search" onclick="addUser()"> <svg...> </svg> </button> <div id="usersList"></div> </div> </div> </body> </html>

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!