$(document).ready(function(){ for (var i = 0; i < x.length; i++) { $("main").append('
' + x[i] + ''); } $( function() { $( ".draggable" ).draggable(); }); var words = document.querySelectorAll(".movable"); for (var e = 0; e < words.length; e++){ var span = words[e]; span.classList.add("draggable"); } });