Write a function into Javascript that will toggle display a HTML element.

 Posted by Raja on 4/15/2008 | Category: .NET Framework Interview questions | Views: 8648
Answer:

function ShowHide(id)

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


We can call this function like
<a href="#" onclick="ShowHide('divid')">Show/Hide</a>

If the "divid" is already displaying on the page it will hide if not it will show on the page and so on.


Asked In: Many interviews | Alert Moderator 

Comments or Responses

Login to post response