PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, October 16, 2022

[FIXED] How to close the table on click in JavaScript?

 October 16, 2022     dom, dom-events, javascript     No comments   

Issue

I have a table which takes the user details. The code is as follows:

<table id="record" border=1>
    <tr>
        <td>Emp Name</td> 
        <td><input type="text" placeholder="Employee Name"></td>
    </tr>
    <tr>
        <td>Address</td>
        <td><input type="text" placeholder="Address"></td>
    </tr>
    <tr>
        <td></td>
        <td>
            <input type="button" value="Add">
            <input type="button" value="Cancel">
        </td>
    </tr>
</table>

Now, when I click on the Cancel button, the table should close. How can I do this?


Solution

Just give the input button an id...

   <input type="button" id="close" value="cancel">

Then add some Jquery...(assuming you are using jquery)

 $(document).ready(function(){

    $('#close').click(function(){$('#record').hide();});

 });

DEMO HERE

Or theres the one liner...

  <input type="button" value="cancel" onclick="$('#record').hide();">

DEMO 2

EDIT

And....Your request for just pure javascript...

<input type="button" id="close" value="Cancel" onclick=" document.getElementById('record').style.display = 'none';">

DEMO 3



Answered By - Kylie
Answer Checked By - Senaida (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

1,216,155

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © 2025 PHPFixing