Display And Hide Div,Span Elements or HTML Elements or Tags (Use Of style.display)

62 views

For hidding or display element inside body tag or for hiding HTML tag, we generally use display method with element id or name.Simply write document.getElementById(elementid).style.display=’none’ for hiding element and document.getElementById(elementid).style.display=” to redisplay that element.we can name of the element in place of getElementById(elementid) document.formname.elementname.style.display=” or ‘none’

use:
style.display

  1. <table id="table_id">
  2. <tr>
  3.   <td>Content Of table
  4.   </td>
  5. </tr>
  6. <tr>
  7.   <td>
  8.    <input type="text" name="name" id="name">
  9.   </td>
  10. </tr>
  11. </table>
  12. <input type="button" value="hide table" onclick="getElementById(’table_id’).style.display=’none’">
  13. <input type="button" value="show table" onclick="getElementById(’table_id’).style.display=”">
  14. <input type="button" value="hide only text box" onclick="getElementById(’name’).style.display=’none’">
  15. <input type="button" value="show only text box" onclick="getElementById(’name’).style.display=”">

Demo:

Content Of table:Simply write document.getElementById(elementid).style.display=’none’ for hiding element and document.getElementById(elementid).style.display=” to redisplay that element.we can name of the element in place of getElementById(elementid) document.formname.elementname.style.display=” or ‘none’



« focus the form element using focus() Use Of Style Attribute in javascript (use of css) »
Posted on Wednesday, April 8th, 2009 at 4:08 pm under Javascript | RSS 2.0 Feed

Post Comment

You must be logged in to post a comment.



ComputerEducationWorld.com All Rights Reserved © RSS | CBSE | Education Boards Of India | What is My IP?