As a lightweight JS library, jQuery is favored by Web developers with the popularity of JavaScr into pt scripts. This article will share with you five useful jquery tips. If you need some useful tips, you can refer to the tips below. Although the effects are not new, they are encapsulated by jQuery, HTML implements a lot of cleansing. 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 script 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.