Categories
Friends
Links
Category Archives: jQuery
How to Display Latest Tweet
$.getJSON("http://twitter.com/statuses/user_timeline/username.json?callback=?", function(data) { $("#twitter").html(data[0].text); });
How to Check if Element Exists
if ( $(‘#myElement’).length > 0 ) { // it exists }
Discover Document Links And Apply Class Automatically
$(‘a[href]‘).each(function() { if((C = $(this).attr(‘href’).match(/[.](doc|xls|pdf)$/))) { $(this).addClass(C[1]); } });
How to Equalize Heights of Divs
var maxHeight = 0; $("div").each(function(){ if ($(this).height() > maxHeight) { maxHeight = $(this).height(); } }); $("div").height(maxHeight);
How to make the entire div clickable
First, find a link inside div class “myDiv”, then redirects to the link when anywhere in div is clicked. jQuery $(".myDiv").click(function(){ window.location=$(this).find("a").attr("href"); return false; }); HTML Example <div class="myDiv"> <p>Loren Ipsun dolor dummy text.</p> <a href="http://www.fabriziomichels.com">My Site</a> </div>
How to create a very simple accordion menu with jQuery