yajRs yajRs - 2 months ago 16
jQuery Question

How to access input elements which were created by jquery

I want to create an upload form, wich always presents a new file input, when filled out. I tried to make this work by creating new inputs but it just works once.
Here is the code:

<head><script type="text/javascript" src="jquery-1.7.2.min.js"></script></head>
<body><form>
<div id="to"></div>
---
<div id="from"><input type="file" class="new"></div>
</form>
<script type="text/javascript">
$('.new').change(function() {
$('.new').appendTo('#to').removeClass('new');
$('#from').append('<input type="file" class="new">');
});
</script>
</body>


Thanks for your help.

Answer Source
<script type="text/javascript">
  $('.new').live('change',function() {
    $('.new').appendTo('#to').removeClass('new');
    $('#from').append('<input type="file" class="new">');
  });
</script>