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

Name:

Email:

Location:

URL:

Smileys

Remember my personal information

Notify me of follow-up comments?

Submit the word you see below:


<< Back to main