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

168
Views
¿Por qué no se agrega mi elemento a la página?

Quiero agregar un elemento de entrada en el árbol DOM con un atributo de tipo = texto con jQuery. Sin embargo, parece que no funciona. El árbol DOM es el mismo y no hay errores de consola.

 $(document).ready(function() { var $code = $("#command"); var $text = $("#itemtext"); var $count = $('#count'); var $add = $('add'); $add.click(function() { $("#items").last().after('<input type="text" id="itemtext" />'); }); $("#generatebutton").click(function() { $code.text('/give @p bundle{Items:[{id:' + $text.val() + ',Count:' + $count.val() + '}]}'); }); });
 <body> <h1 id="title">Bundle Generator for mc</h1> <div id="items"> <input type="text" placeholder="item name" id="itemtext"> <input type="number" min="-128" max="127" id="count"> <button id="addslot">Add slot</button> <button id="generatebutton">Generate!</button> </div> <h2>Your command is here!</h2> <p id="command"></p> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> </body>

esta línea:

 $("#items").last().after('<input type="text" id="itemtext" />');

no funciona, alguien me puede ayudar?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Ha mencionado una id que no está en DOM. ¿Quizás está buscando el espacio de addslot en lugar de add ? Además, no hay indicación de id ('#') en var $add = $('add') .

 $(document).ready(function() { var $code = $("#command"); var $text = $("#itemtext"); var $count = $('#count'); var $add = $('#addslot'); $add.click(function() { $("#items").last().after('<input type="text" id="itemtext" />'); }); $("#generatebutton").click(function() { $code.text('/give @p bundle{Items:[{id:' + $text.val() + ',Count:' + $count.val() + '}]}'); }); });
 <body> <h1 id="title">Bundle Generator for mc</h1> <div id="items"> <input type="text" placeholder="item name" id="itemtext"> <input type="number" min="-128" max="127" id="count"> <button id="addslot">Add slot</button> <button id="generatebutton">Generate!</button> </div> <h2>Your command is here!</h2> <p id="command"></p> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> </body>

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