How could I hide the 'Edit'-link after I press it? and also can I hide the "lorem ipsum" text when I press edit?
<script type="text/javascript"> function showStuff(id) { document.getElementById(id).style.display = 'block'; } </script> <td class="post"> <a href="#" onclick="showStuff('answer1'); return false;">Edit</a> <span id="answer1" style="display: none;"> <textarea rows="10" cols="115"></textarea> </span> Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum </td>
Style display property is used to hide and show the content of HTML DOM by accessing the DOM element using JavaScript/jQuery. To hide an element, set the style display property to “none”. document. getElementById("element").
You can also use this code to show/hide elements: document. getElementById(id). style.
Using Css style we can hide or show HTML elements in javascript. Css provides properties such as block and none to hide/show the HTML elements.
function showStuff(id, text, btn) { document.getElementById(id).style.display = 'block'; // hide the lorem ipsum text document.getElementById(text).style.display = 'none'; // hide the link btn.style.display = 'none'; }
<td class="post"> <a href="#" onclick="showStuff('answer1', 'text1', this); return false;">Edit</a> <span id="answer1" style="display: none;"> <textarea rows="10" cols="115"></textarea> </span> <span id="text1">Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum</span> </td>
You can also use this code to show/hide elements:
document.getElementById(id).style.visibility = "hidden"; document.getElementById(id).style.visibility = "visible";
Note The difference between style.visibility
and style.display
is when using visibility:hidden unlike display:none, the tag is not visible, but space is allocated for it on the page. The tag is rendered, it just isn't seen on the page.
See this link to see the differences.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With