How to toggle display an HTML element?

 Posted by Raja on 6/29/2008 | Category: JavaScript Interview questions | Views: 11963
Answer:

Call following function

function ToggleFollowingText(id)

{
document.getElementById(id).style.display == '' ? document.getElementById(id).style.display = 'none' : document.getElementById(id).style.display = '';
}


In above function you need to pass id of the html element as the parameter.
If the control is already displaying then it will hide otherwise it will be shown.


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response