Quantcast

5 useful jquery tricks every web developer should know

jquery-logo

Hello developers.  We really find jquery  a good framework and find out really good tricks which every web developer should know.

Here is the list:

1. Disable right-click menu:

?View Code JAVASCRIPT
1
2
3
4
5
$(document).ready(function(){
    $(document).bind("contextmenu",function(e){
        return false;
    });
});

.

2. Making your content Flash (Blink):

?View Code JAVASCRIPT
1
2
3
4
5
6
7
8
jQuery.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. Document ready alternative:

?View Code JAVASCRIPT
1
2
3
$(function(){
	//document is ready do something
});

.

4. Detect Browser:

?View Code JAVASCRIPT
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// 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. Check for Element existence:

?View Code JAVASCRIPT
1
2
3
if ($("#someDiv").length) {
    //yes it does ,do something
}

Thats it!!
Cheers!


Stumbleupon
Delicious

Comments

12.18.09

thanks, this is very useful.

12.18.09

Are you serious? Not useful or anything I need to know.

12.18.09

With regards to: 2. Making your content Flash (Blink)

The blink tag was removed for a reason, this is certainly NOT something ‘good’ web developers should know how to do if they build properly accessible websites!

12.18.09

Thanks, the last one is helpful pretty often :)

12.18.09

Thanks Reshe for bookmarking this post in delicious.

12.18.09

Thanks Simon.

12.18.09

Small list tips :)

12.18.09

Some interesting and intelligent content you have here on your site. I have several wordpress sites and like your theme. I do notice that you are not monetising your traffic to its maximum which is what I used to do until someone pointed out to me that you can actually earn yourself some decent amounts to help pay your hosting and domain fees etc. Looking at your Alexa rankings I can see you obtain some decent traffic which for very little work could help you out. I use this Wordpress Plugin which effectively turns words and phrases in all (or just some if you like) your content, making contexual links which your visitors will click upon. Take a look at it and see what I mean, I easily clear my hosting and other fees each month using this. Hope that helps you out – we fellow wordpress bloggers have to stick together!

12.18.09

What’s wrong with this, it converts object to boolean:

if ( $(“#someDiv”) ) {
//yes it does ,do something
}

12.18.09

I was just talking with my coworker about this yesterday over lunch . Don’t know how in the world we landed on the subject really, they brought it up. I do recall having a excellent steak salad with cranberries on it. I digress…

12.18.09

Heh, I have to admit that the above comment is a good example of clever spam.

The disable right-click menu, is this the first step towards stopping people from nicking images from various websites???

$.browser is deprecated, just a heads-up.

$.support is the best way to code for browser-specific features.

Do you really think flashing text is helpful? I can’t think of that and i can’t find any example on your page.
Also disabling right-click will conflict with user experience.
Maybe you can try it. You probably will loose some readers?

jQuery is such a powerful tool, but you have to use it with caution.

Leave Your Response

* Name, Email, Comment are Required

Trackbacks and Pingbacks