How to expanding and collapsing a division using JavaScript/jquery

Dear Experts,

I am new to JavaScript, i want to implement a task that, hide/show or expanding/collapsing a division using javascript / jquery.

Kindly provide the required code.
prabhuallaAsked:
Who is Participating?
 
GreggCommented:
0
 
Roger BaklundCommented:
Plain javascript:

function Toggle(id) {
  var o=document.getElementById(id);
  o.style.display = (o.style.display == 'none') ? 'block' : 'none';
}

Open in new window


Usage:

<button onclick="Toggle('TheDiv')">On/off</button>
<div id="TheDiv">Hello!</div>

Open in new window

0
 
prabhuallaAuthor Commented:
thanks for the solution
0
 
Roger BaklundCommented:
Did you try my code?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.