I think you want .prepnd()
, not .after()
to make it the first child element.
$(document).on('click', '.add-picture', function() {
var imageField = $('<img class="link" >');
$(this).parent().find(".step-wrapper").prepend(imageField);
});
See the jQuery doc for .prepend()
.
Though this style of code works, you could also use .closest()
for slightly more robust code:
$(document).on('click', '.add-picture', function() {
var imageField = $('<img class="link" >');
$(this).closest(".step").find(".step-wrapper").prepend(imageField);
});