5 tricks on Jquery.

5 tricks on Jquery.

Sep 25

Jquery is as usual the best you can get with plugins as well as the sheer joy of writing short and sweet. In this post I talk about 5 re-used Jquery snippets across projects. Some of this may not be news to you, but for some it might just make you a “jfan”

Hide those selects

There might be the bgIframe’s and other creative solutions to the “select” box bleed issue, but if you still had trouble. I had trouble with bgIframe , try the traditional hide all select boxes trick.

1
2
3
4
5
6
function selectToggle(){ 
$(”select”).each(
function(){ 
$(this).toggle();
} 
}

In our mouseout and mouseover functions just call the “selectToggle()” function.

Wrap them up

Use the “wrap” method to wrap elements with other elements. How about a shadow at runtime, no problem.

1
$(”mydiv”).wrap(<div class="shadow"><div class=’innershadow’></div></div>);

Measure Everything

Use the excellent “dimensions ” suite to get dimensions of elements. Now isn’t the following easy.

1
2
var position = {};
 $(”#myElement”).position(position);

Results

1
position = { top: 10, left: 10 }

Anything goes

How about $(”#myelement”) or $(”.myClass”) or $(”.myclass li”) or plain $().

Super of Suckerfish.

How do you take

  • Header
    • Sub-menu 1
    • Sub-menu 2

and make it into an suckerfish menu, simple, call the superfish :

How about

$(”#nav”).superfish();

Hope you enjoyed my writeup on Jquery, I have stopped Dojoing a while back and I am warming up to the “J”.

Leave a Reply