samedi 18 avril 2015

Multifucntion toggle function in javascript

I'm using following JavaScript code to slideUp and slideDown different divs based on theirs link options:



function toggleDiv(option) {
$('.content-box').slideUp();
$('#' + option).slideDown(300);
}

<li><a class="active" href="javascript:toggleDiv('toggle1')">Toggle 1</a></li>
<li><a href="javascript:toggleDiv('toggle2')">Toggle 2</a></li>


The whole code works perfectly, however what I would like to do is that the class="active" switches to the actual link that user has pressed. I heard about some attribute method or something similiar bur have no ideea how to proceed. So I would appriciate any help from you.


By the way, why is the code working smoothly in Firefox/Chrome but is laggy in Safari?


Check the JSFiddle here: http://ift.tt/1EVUhku For some reason it won't work in JSFiddle but the same code works fine in a normal .html file.


Aucun commentaire:

Enregistrer un commentaire