All jQuery Tips

OOPS!!!! jQuery Selectors NOT working…

OOPS!!!! jQuery Selectors NOT working.. A very common jQuery problem/issue that you must have face or may face. And there could be tons of reason of selectors not working properly like incorrect syntax, incorrect context.. But do you know there could be another reason which is element ID or css class name? Yes, you read […]
Read the rest of this entry »

jQuery Namespacing with on() and off() method

With jQuery 1.7, jQuery team introduced 2 new ways to attach and remove events. on() method is used for attaching events to DOM elements, and off() method is used to removed event handlers. And you should use on() and off() only to attach and remove handlers, instead of bind(), live() and delegate(). Related Post: bind() […]
Read the rest of this entry »

Common jQuery Mistakes

Well, Everyone makes mistakes and and best part would be not to repeat them again. You should "Always make new mistakes" :). jQuery is awesome library. But believe me, it can make you crazy if it is not used properly and efficiently. It can hit performance of your page and you don't even realize it. […]
Read the rest of this entry »

jQuery to round off decimal values

To round off decimal values using jQuery, we can use the built-in JavaScript methods toFixed() or toPrecision(). The toFixed() method converts a number into a string, keeping a specified number of decimals. var iNum = 12345.6789; iNum.toFixed(); // Returns "12346": note rounding, no fractional part iNum.toFixed(1); // Returns "12345.7": note rounding iNum.toFixed(6); // Returns "12345.678900": […]
Read the rest of this entry »

jQuery code to disable double click event

jQuery code to disable double click event on the webpage. $(document).ready(function(){ $("*").dblclick(function(e){ e.preventDefault(); }); }); Above jQuery code will disable double click event for all the controls on the webpage. If you want to disable for specific control, let's say a button with ID "btnSubmit" then, $(document).ready(function(){ $('#btnSubmit').dblclick(function(e){ e.preventDefault(); }); }); Feel free to contact […]
Read the rest of this entry »

jQuery to clear textbox value using ESC key

Yesterday worked on interesting thing. Requirement was to clear the textbox text when escape (Esc) key is pressed within textbox. This was easy and simple. Bind keyup event with textbox/textboxes. Check the keycode. If keyCode is 27 (which is for esc key) then clear the text. $(document).ready(function() { $('input[type="text"]').keyup(function(e){ if(e.keyCode == 27) { $(this).val(''); } […]
Read the rest of this entry »

Responsive Menu
Add more content here...