Expand with JavaScript; Link without JavaScript
Over at GodBit, someone needed to show a div when a heading was clicked, but if the user didn’t have javascript, the heading was a link to a detail page. This sounded like an interesting idea, so I poked around and here is what I ended up with:
$(document).ready(function(){
$("h3 a").parent().next("div").hide();
$("h3 a").click(function() {
$("h3 a").parent().next("div").slideToggle();
return false;
})
});
The key here is return false;—that stops the click from triggering the link.
Posted by on 04/07 at 08:37 PM
Next entry: New jQuery UI release 1.5b4
Previous entry: Implementing IE min-width with Javascript