All jQuery Codes

How to make readonly textbox using Jquery

Sometimes making a textbox readonly is project need. There are 2 ways to make textbox readonly using jQuery. Method 1: <script type="text/javascript"> $(document).ready(function(){ $("#<%=txtName.ClientID %>").focus(function () { $(this).blur(); }); }); </script> See live Demo and Code Method 2: <script type="text/javascript"> $(document).ready(function(){ $("#<%=txtName.ClientID %>").attr('readonly', true); }); </script> Feel free to contact me for any help related […]
Read the rest of this entry »

jQuery code to allow only numbers in textbox

Below jQuery code snippets will allow only numbers in the textbox. However backspace and delete keys are also allowed. $(document).ready(function(){ $("#<%= txtNumbers.ClientID%>").keydown(function(e) { if (e.shiftKey) e.preventDefault(); else { var nKeyCode = e.keyCode; //Ignore Backspace and Tab keys if (nKeyCode == 8 || nKeyCode == 9) return; if (nKeyCode < 95) { if (nKeyCode < 48 […]
Read the rest of this entry »

Call jQuery from Javascript function

Have you ever come accross a situation where you need to call Jquery from or within a Javascript function? Well, it's not that tough either. You can directly write your jQuery code within a JavaScript function. See below code. I have placed a button on my page which makes a call to a Javascript function […]
Read the rest of this entry »

Find control with CSS class

jQuery provides a very cool mechanism to find the control of the page with the class name. Let's say you want to find out all the a tags which are having "sample" as Css class. jQuery has really made life simple for programmers. Below given code does exactly the same thing. It also adds the […]
Read the rest of this entry »

Hide all elements of HTML form using jQuery

If you want to hide all the elements of the form then below jQuery code will help you to achieve this. <script type="text/javascript"> $(document).ready(function(){ $("#form1").hide() }); </script> "form1" is the Id of the HTML form. Hide() function can be used with any control. If you don't want to hide all the elements of the form […]
Read the rest of this entry »

Disable/Enable an element using jQuery

You must have come across a situation where you have to make any element disable or enable.There are couple of ways using them you can enable/disable any element using jquery. jQuery really makes your task very easy. In below given example, I have disabled a textbox with id "txtName". Approach 1 $("#txtName").attr("disabled", true); Approach 2 […]
Read the rest of this entry »

Responsive Menu
Add more content here...