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!

Like It? Share it.

                                                       


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

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???

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.

12.18.09

I totally agree with GDevelop. Disabling right click is not a good idea. and no one would come back to your site and that visitor will try to move another site.

12.18.09

I am a web developer and I am doing very well, without knowing this. Maybe it’s not a MUST.

12.18.09

I’d like to submit that #3, the “document ready alternative”, should be taken out and shot.

It’s an ugly, non-intuitive, difficult-to-grep-for construct that does exactly the same thing as something that’s very memorable and very easy to grep for.

What’s the point of saving a few characters, at the expense of clarity?

Eschew obfuscation!

I am so impressed w/evernote so far. really pro stuff. thx folks

this really great

Thanks for the great info and hope it helped others at least like it helped me. All the best.

Great tips. Thanks for sharing.

12.18.09

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

12.18.09

Good job, I certainly couldn’t put together a list like this. I think of myself as a classical guy myself, but I wouldn’t have minded seeing more computer-centered names on the list, though I’m at a loss as to whom to place.

12.18.09

I want to say that after reading your post I have found so many interesting thing in your blog and I really love that. Keep up the good work!

12.18.09

A topic close to my heart thanks. Like your blog design too.

12.18.09

Great piece! Any pespectives that you may be able to voice to justify your last section a small bit further? nice one

12.18.09

Informative writing! Are there any pespectives that you maybe willing to voice in order to help us understand the second point a small bit more? nice one

12.18.09

Nice of you to show what it could have taking you months to learn about it. From people like you we get t odevelop the entire world of web developing.

Good article and post. I really thanks to the author!

12.18.09

Nice post.Thank you for taking the time to publish this information very useful!
I’m still waiting for some interesting thoughts from your side in your next post thanks

12.18.09

Hi, usually great to see other folks from the hole world in my browsing, I genuinely appreciate the time it should have taken to set together this great blog. kind regards

Some of them are very useful, thanks!

It’s mind boggling how many videos and news come out on a weekly basis.

12.18.09

Pretty good post

This is such a beautiful craft. Thank you for the post.

Leave Your Response

* Name, Email, Comment are Required