0

HTML:

<input type="file" id="flIcon" />

In Jquery:

$('#btnAddNew').click(function(event) {
                    alert($("#flIcon").attr('file'));
                    $("div#flIcon").replaceWith("<input type='file' id='flIcon'/>");

                });

I see in FireBug when page Load:

<div id="uniform-flIcon" class="uploader">
<input id="flIcon" class=" " type="file" style="opacity: 0;">
<span class="filename" style="-moz-user-select: none;">document-save.png</span>
<span class="action" style="-moz-user-select: none;">Choose File</span>
</div>

I try it from this ref.Clearing <input type='file' /> using jQueryBut its not work for me.Is there any browser compatibility issue or i am missing some thing.Thanks.

2
  • its working fine with $("#flIcon").replaceWith('..'); here---jsfiddle.net/XFyuw/3 Commented Mar 2, 2012 at 7:32
  • $('#btnAddNew').on('click(function(event){ alert($("#flIcon").attr('file')); $("div#flIcon").replaceWith("<input type='file' id='flIcon' />"); }); Commented Mar 2, 2012 at 7:34

2 Answers 2

1

Try like this:

<input type="file" id="flIcon" />
<div id="btnAddNew">Clear</div>

and then:

$('#btnAddNew').click(function(event) {
    $("#flIcon").replaceWith("<input type='file' id='flIcon'/>").html();
});​
Sign up to request clarification or add additional context in comments.

Comments

0

Yes Darin's solution works well.

Alternatively you could also clear by doing this using JQuery..

$('#flIcon').val('');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.