As I already made comments on this, I made a quick google and came across this post, which could make it a little easier. Detect all changes to <input type = "text"> (immediately) using jQuery
So, I put the fiddle here for testing: Minor modified version
HTML
<input type="text" value="Some Value" id="text1" /> <button id="btn1">Click Me</button>
Js
$('#text1').each(function() { var elem = $(this); elem.data('oldVal', elem.val()); elem.bind("propertychange change click keyup input paste", function(event){ if (elem.data('oldVal') != elem.val()) { if (elem.val().length == 0 ) { $("#btn1").hide(); } else { $("#btn1").show(); } elem.data('oldVal', elem.val()); } }); });
As I donβt need a lot of time to partition this code ... In appearance .. You donβt need elem.data ... Just a binding event ... ... oh, it looks like I decided to cut the code for you. ..
http://jsfiddle.net/z2ew3fqz/3/ Using the same HTML ...
The shortest version I could make from the above example
HTML
<input type="text" value="Some Value" id="text1" /> <button id="btn1">Click Me</button>
Js
$('#text1').bind("propertychange change click keyup input paste", function(event){ if ($(this).val().length == 0 ) { $("#btn1").hide(); } else { $("#btn1").show(); } });
I quickly checked this for chrome .. the mouse keys / functions all seem to affect it correctly ... Other browsers I will leave before the OP for testing. Let me know if there are any problems in a specific browser ..
IE10 seems to be minimal support for this. IE9 may have a js prototype. But how important is it to support your project? to support IE <10 <
source share