1

jquery.min.js is working fine, but when I replace jquery.min.js with jquery.1.9.js, my code is not working.

<script src="jquery.min.js" type="text/javascript"></script>
<script>
$('#imageFile').live("change", function () {
    $("#imageSize").text("");
    var tt = $(this).val();
    var size = this.files[0].size;
    $("#imageFile").val(Math.ceil(size / 1024));
});
</script>
<input id="imageFile" type="file" />
<input id="imageSize" type="text" />
dsgriffin
  • 66,495
  • 17
  • 137
  • 137
  • 2
    You don't even have to use `.live` here. Just put the script after the elements and bind the event handler normally. – Felix Kling Jun 02 '13 at 17:47
  • possible duplicate of [jQuery 1.9 .live() is not a function](http://stackoverflow.com/questions/14354040/jquery-1-9-live-is-not-a-function) – Felix Kling Jun 02 '13 at 18:10

2 Answers2

4

Because live() has removed as of jQuery 1.9. Use on() instead. Please see the linked documentation for more information.

dsgriffin
  • 66,495
  • 17
  • 137
  • 137
  • thanx for your reply, but i have to use jquery.1.9.js, then what change i have to make to work with 1.9? – Adeeb Keyaam Jun 02 '13 at 17:47
  • 2
    @Adeeb: As the answer says, you have to use `.on`. Have a look at the documentation. Maybe this helps as well: [jQuery 1.7 - Turning live() into on()](http://stackoverflow.com/q/8021436/218196). – Felix Kling Jun 02 '13 at 17:48
  • 4
    @Adeeb: Then you might have not done it correctly. Are you sure you read the documentation? The `.live` documentation shows the equivalent code with `.on`. Also have a look at the question I linked to. – Felix Kling Jun 02 '13 at 17:51
  • @AdeebKeyaam just making sure, you do actually have the jquery1.9 script in that folder right? – Ben McCormick Jun 02 '13 at 18:07
  • thank you to all and appreciated your comments and reply...it is working, i am done a terrible mistake, in pressure, i didn't focus that i edit a new page and display the old one...how stupid i am...thanx to everybody again... – Adeeb Keyaam Jun 02 '13 at 18:47
1

Use the on() method:

 $(document).on("change", "#imageFile", function(){

  $("#imageSize").text("");
    var tt = $(this).val();
    var size = this.files[0].size;
    $("#imageFile").val(Math.ceil(size / 1024));


 }); 

See the documentation here

isJustMe
  • 5,452
  • 2
  • 31
  • 47
  • 1
    If you mean your code should just replace the OP's code, then this wouldn't work. The elements are not available yet when the code is executed. – Felix Kling Jun 02 '13 at 18:04
  • 1
    I though the elements were already there, anyway I edited and it should work at anytime – isJustMe Jun 02 '13 at 18:06