prop() method in jQuery
The prop()
method used to Get and Set Property value of selected element.
Syntax
//get cheked status of input $("#chk").prop("cheked"); //set input cheked to true $("#chk").prop("cheked",true);
Example
The following example shows, how to disable and enable input using jQuery prop()
method.
Demo
<html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> </head> <body> <input type='checkbox' id='chk'> <input type='text' id='txt' value='12345' disabled> <script> $(document).ready(function(){ $("#chk").click(function(){ var status=$(this).prop("checked"); if(status==true){ $("#txt").prop("disabled",false); }else{ $("#txt").prop("disabled",true); } }); }); </script> </body> </html>Try it Yourself