0

The jQuery file change event is not working in IE, yet works perfectly in Safari, Firefox etc. Can anyone tell me why this is?

<script language="javascript" src="jquery.js"></script>    
<script language="javascript">  
    $(document).ready(function() {
        $('.m_file').live('change',function() {
        alert("Changed");
    });
</script>

<input type="file" name="m_file" id="m_file" class="m_file" />
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
ramesh
  • 4,008
  • 13
  • 72
  • 117

1 Answers1

-1

TRY:

$('.m_file').change(function(){
alert("Changed");
});
Kevin Bowersox
  • 93,289
  • 19
  • 159
  • 189
  • 1
    Any reason for docking this answer? – Kevin Bowersox Apr 03 '12 at 12:41
  • 1
    I'd imagine it's because this is no different to what the OP already has, and won't help. Look at the duplicate question links in the OP comments for the fix for this. Wasn't me who downvoted BTW. – Rory McCrossan Apr 03 '12 at 12:44
  • Adding the input fields dynamically using jQuery . So "live" is needed.. Please help – ramesh Apr 03 '12 at 12:45
  • Apart from the duplicate questions, could you provide some explanation for why `change()` should work where `live('change', ...)` fails? – Felix Kling Apr 03 '12 at 12:46
  • 2
    @rajeeesh: `live` is not *needed* if you add elements dynamically. It is more convenient sometimes, that's all. You can always add event handlers once you created the element. – Felix Kling Apr 03 '12 at 12:47
  • 1
    @Felix Kling I used .change() because it worked for me in code I wrote yesterday, in IE7+ and FF. Using jquery 1.8 – Kevin Bowersox Apr 03 '12 at 12:53
  • 1
    .live() is deprecated anyway, take a look at .on() – ryan j Apr 03 '12 at 12:55
  • 1
    But what's the explanation? According to the documentation, it should work with `live` as well. *edit:* Apparently there are problems and using `delegate` or `on` should solve it as well. – Felix Kling Apr 03 '12 at 13:35
  • @Felix Kling can you please give me a little help on event handlers ? thanks for the reply guys – ramesh Apr 04 '12 at 07:47
  • 1
    @rajeeesh: Don't know what kind of help you expect. Have a look at the jQuery documentation of [`.on()`](http://api.jquery.com/on/) and if you want to learn how events work in general, I recommend to read the [articles on quirksmode.org](http://www.quirksmode.org/js/introevents.html). – Felix Kling Apr 04 '12 at 08:23