Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove keypress from input with jquery?

Tags:

jquery

Does anyone know how can I remove keypress from input with jquery?

Example:

<input type="text" keypress="cleanMsg()" id="cleanMsg" name="cleanMsg">

How can I removed the keypress="cleanMsg()" from input by using jquery? Or anyway to replace keypress="cleanMsg()" to keypress="Msg()"??

like image 991
Jin Yong Avatar asked Oct 14 '09 03:10

Jin Yong


1 Answers

I assume you mean "how do you remove the 'keypress' attribute from the input", in which case this would work

<script>
    $(document).ready(function(){
        $("#cleanMsg").removeAttr("keypress");
    });
</script>

If you want to bind to a keypress, you should do it in the jQuery way (refer to the docs), with this code the above attribute within the input tag is redundant

<script>
    $(document).ready(function(){
        $("#cleanMsg").keypress(function(){
            //do something here
        });
    });
</script>
like image 167
wiifm Avatar answered Sep 22 '22 14:09

wiifm