I have HTML like this:
<span class="file-wrapper" id="fileSpan"> <input type="file" name="photo[]" id="photo" /> <span class="button">Click to choose photo</span> </span>
I want to extract the input field from there, change its ID and put it in an other div.
How can I do that? If jQuery is needed that's okay, but if it can be without that would be great.
It's certainly easy in jQuery:
// jQuery 1.6+ $("#photo").prop("id", "newId").appendTo("#someOtherDiv"); // jQuery (all versions) $("#photo").attr("id", "newId").appendTo("#someOtherDiv");
Working demo: http://jsfiddle.net/AndyE/a93Az/
var photo = document.getElementById("photo"); photo.id = "newId"; document.getElementById("someOtherDiv").appendChild(photo);
Working demo: http://jsfiddle.net/AndyE/a93Az/1/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With