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

169
Views
Why isn't my element being added to the page?

I want to add a input element on the DOM tree with an attribute of type=text with jQuery. However it seems to not work. The DOM tree is the same and no console errors.

$(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>

this line:

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

doesn't work, can anyone help me?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You have mentioned an id that isn't in DOM. Maybe you are looking for addslot instead of add? Also there is no indication of id ('#') in 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!