Ok, i have input object, when it is changed it adds another one..
also there is delete (izdzēst) link when you click on, it should remove last input field..
how to that? (the function for delete is dzest )
I guess the problem is in $(this)?
<input name="userfile[]" type="file" size=40 />
<a href="#" onclick="dzest();return false" class="link" name="dzest" style="font-weight:normal; display:none;">Izdzēst</a><br />
<script>
function dzest(){
$(this).closest('input').remove();
}
$("input[type=file]").change(function() {
$('<input name="userfile[]" type="file" />').appendTo('body');
$('<a href="#" onclick="dzest();return false" class="link" name="dzest" style="font-weight:normal; display:inline;">Izdzēst</a><br/>').appendTo('body');
$('.link').css('display','inline');
});
</script>
thisin your code refers to thewindowobject and not the anchor.closestmeans the closest element parent,inputcan never be a parent, so you probably meantprev()Fixed Code
And the function:
You can also use unobtrusive event handlers & delegate events.