Home >Web Front-end >JS Tutorial >How to Hide Elements (including the Triggering Element) After JavaScript Interaction?
In HTML, elements can be hidden or shown using the display property of CSS. By manipulating this property with JavaScript, developers can toggle the visibility of elements dynamically.
In the provided code snippet, the function showStuff() is triggered when the "Edit" link is clicked. This function unhides the textarea element, which is initially hidden using the display: none; style.
However, the question also asks how to hide both the "Edit" link and the "Lorem ipsum" text. To achieve this, the showStuff() function can be modified as follows:
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'; }
In this updated function:
In the updated HTML code, the same function is called with additional parameters:
<td>
Now, when the "Edit" link is clicked, not only will the textarea become visible but both the "Lorem ipsum" text and the "Edit" link itself will be hidden. This demonstrates how JavaScript can be used to manipulate the visibility of multiple elements in a single function call.
The above is the detailed content of How to Hide Elements (including the Triggering Element) After JavaScript Interaction?. For more information, please follow other related articles on the PHP Chinese website!