
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:
1 2 3 4 5 | $(document).ready(function(){ $(document).bind("contextmenu",function(e){ return false; }); }); |
.
2. Making your content Flash (Blink):
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:
1 2 3 | $(function(){ //document is ready do something }); |
.
4. Detect Browser:
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:
1 2 3 | if ($("#someDiv").length) { //yes it does ,do something } |
Thats it!!
Cheers!











Comments
thanks, this is very useful.
Are you serious? Not useful or anything I need to know.
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!
Thanks, the last one is helpful pretty often
Thanks Reshe for bookmarking this post in delicious.
Thanks Simon.
Small list tips
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!
What’s wrong with this, it converts object to boolean:
if ( $(“#someDiv”) ) {
//yes it does ,do something
}
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…
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.