Five useful jquery tips _ jquery

Source: Internet
Author: User
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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.