Andrew
Andrew

Reputation: 83

jquery append() not working

I have this really simple fiddle set up, if someone could point out why it's not working I'd really appreciate it, been struggling to figure this out for some time now.

Here's the code:

$('input[type=file]').change(function () {
    if ($(this).val()) {
        alert('This thing works.');
        $(this).append('<input type="file" name="test">');
    } else {
        $(this).remove();
    }
});

Also, Fiddle Link

Upvotes: 0

Views: 90

Answers (3)

Jai
Jai

Reputation: 74738

use .after() or .before() or .inserAfter():

$(this).after('<input type="file" name="test">');

Upvotes: 1

Tamil Selvan C
Tamil Selvan C

Reputation: 20199

You can't append anything to input element

Upvotes: 2

helion3
helion3

Reputation: 37381

You can't append anything to an input, use .after or .replaceWith. The input is an element that may not contain child elements.

Upvotes: 6

Related Questions