Within my web application, I am dynamically changing the style of an HTML element using JavaScript.
Below is the code snippet:
function layout() {
if(document.getElementById('sh1').getAttribute('src') == "abc.png") {
document.getElementById("sh1").style.display="none";
} else {
document.getElementById("sh1").style.display="block";
}
}
The corresponding HTML code is:
<img id="sh1" src="abc.png" />
Now, I want to ensure that if the style of the image element is set to display:none, then the following elements:
<p id="Text1">Name<br />description</p>
also have their style changed to display:none. Similarly, if the image element's style is set to display:block, then the above elements' style should also be updated to display:block automatically.
How can this be achieved?