Skip to content

Instantly share code, notes, and snippets.

@christianhager
Created November 11, 2010 04:49
Show Gist options
  • Save christianhager/672027 to your computer and use it in GitHub Desktop.
Save christianhager/672027 to your computer and use it in GitHub Desktop.
Toggle flere
//en av linkene blir trykket
$(".link").click(function(){
var id = $(this).attr("id"); // henter ut riktig id
showThisBox(id); // vi kaller på funksjonen som viser en, gjemmer de andre
return false; //for å unngå at man hopper i skjermen
});
//vis en, gjem de andre
function showThisBox(id){
//looper alle boksene
$(".box").each(function(){
//vis om det var denne vi skulle vise
if($(this).attr("id")==id){
$(this).show();
//gjem ellers
}else{
$(this).hide();
}
});
}
<a class='link' id='1' href='#'>Link 1</a>
<a class='link' id='2' href='#'>Link 2</a>
<a class='link' id='3' href='#'>Link 3</a>
<div class='box' id='1'> box 1 </div>
<div class='box' id='2'> box 2 </div>
<div class='box' id='3'> box 3 </div>
.box{display:none;}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment