javascript - Adding a button dynamically with JQuery without using .append -


i've got scenario in want button appear, scenario looped over.

my code @ moment looks like:

var r = $('<input type="button" value="done swapping"/>'); $('#doneswapping').append(r); 

i want button appear once, due using .append keeps getting added during each iteration, resulting in several buttons.

is there way around this? maybe removing button again @ end of loop? did try .remove seems remove entire 'doneswapping' reference rather button.

thank :)

you need use .empty() not destroy structure content in side it.

$('#doneswapping').empty();   

.remove() destroy container.


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -