Home > Blockchain >  jQuery Cannot add element
jQuery Cannot add element

Time:10-29

I want to create an element and add to an existing one, but for some reason no element is created, and no error is thrown. I read the documentation, but it doesn't work. Here's the code:

$("#output").add($("<div></div>").add("Hello"));
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="output"></div>
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

CodePudding user response:

Maybe you meant to use append instead of add?

$("#output").append($("<div></div>").append("Hello"));
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="output"></div>
<iframe name="sif2" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

  • Related