user755806
user755806

Reputation: 6815

Equivalent jquery code for existing javascript code?

I am new to jquery. I wrote one javascript method and will be called on click of an anchor.

onclick="return show('contentTwo','content');

here contentTwo and content are div Ids.

method:

function show(shown, hidden) {
  document.getElementById(shown).style.display='block';
  document.getElementById(hidden).style.display='none';
  return false;
}

Now I would like to use jquery's slideDown and slideUp methods than using javascript. how can I convert the above code into jquery?

Thanks!

Upvotes: 0

Views: 60

Answers (3)

Dhaval Marthak
Dhaval Marthak

Reputation: 17366

try this:

DEMO --> http://jsfiddle.net/YFmtc/2/

$("#hidden").hide();
$('a').click(function(){
        $("#shown, #hidden").slideToggle("slow");
});

See API slideToggle()

Upvotes: 1

Arun P Johny
Arun P Johny

Reputation: 388326

Try

function show(shown, hidden) {
  $('#' + shown).show();
  $('#' + hidden).hide();
  return false;
}

or

function show(shown, hidden) {
  $('#' + shown + ',' + '#' + hidden).toggle();
  return false;
}

Upvotes: 0

Suresh Atta
Suresh Atta

Reputation: 121998

Try

$("#shown, #hidden").slideToggle("slow"); 

DEMO

Upvotes: 1

Related Questions