Five useful jquery tips and five jquery tips
Although the effects of the techniques in the following sections are not fresh, HTML is greatly cleaned through jQuery encapsulation. Refreshing, concise, and efficient code is the ultimate goal of developers at any time. Maybe it is simple, but it has a huge amount of energy. Let's take a look at the five very practical jQuery techniques recommended by the Helper's house editor.
1. Right-click Disabled
$(document).ready(function() { $(document).bind("contextmenu", function(e) { return false; });});
Of course, we recommend that you use on () to replace the bind () function after jquery1.7.
2. Make the content flash
$.fn.flash = function(color, duration) { var current = this.css('color'); this.animate( {color: 'rgb(' + color + ')'}, duration / 2); this.animate( {color: current}, duration / 2);}$('#someid').flash('255,0,0', 1000);
3. Simplified DOM Loading
$(function() { // document is ready..})
4. Detect browsers
// Safariif( $.browser.safari ){//do something}//Above IE6if ($.browser.msie && $.browser.version > 6 ){//do something}// IE6 and belowif ($.browser.msie && $.browser.version < 6 ) { //do something } // Firefox 2 and above if ($.browser.mozilla && $.browser.version >= "1.8" ){//do something}
5. determine whether an element exists
if($("#someDiv").length) { // yes it does, do something...}
I have shared with you five useful jquery tips.