Home>

As a lightweight js library, jquery is popular with web developers with the popularity of javascrīpt scripts.This article shares five useful jquery tips,

1. Disable the right mouse button

$(document) .ready (function () {
  $(document) .bind ("contextmenu", function (e) {
    return false;
  });
});

Of course, after jquery version 1.7, the bind () function is recommended to use on () instead.

2. Make 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);

The shorthand form for 3.dom loading completion

$(function () {
  //document is ready ..
})

4. Probe the browser

//safari
if ($.browser.safari)
{
//do something
}
//above ie6
if ($.browser.msie&&$.browser.version>6)
{
//do something
}
//ie6 and below
if ($.browser.msie&&$.browser.version<6) {//do something} //firefox 2 and above if ($.browser.mozilla&&$​​.browser.version>= "1.8 ")
{
//do something
}

5. Determine if the element exists

if ($("#somediv"). length) {
  //yes it does, do something ...
}

I have shared with you five useful jquery tips above, I hope you like it.

  • Previous Detailed ASP encoding and decoding functions
  • Next Android implementation of extended Menu method