I am new to JavaScript, and I've been trying to use a button to show a particular element. I need to be able to clear some content of the page and display new content on the click of a button. I cant change pages, and need to stay on the same page. I am trying to change the display property of the element I want to display.
This is what I have tried:
//CSS//
<style>
p {
display: visible;
}
div {
display: none;
}
</style>
//HTML//
<body>
<p id="textElem">Lorem ipsum dolor sit amet consectetur adipisicing elit.</p>
<button onclick="displayDiv()">View Form</button>
<div id="hiddenElem">
<form></form>
</div>
<body>
//JS//
<script>
const textElement = document.getElementById('textElem');
cont hiddenElement = document.getElementById('hiddenElem');
function displayDiv() {
}
</script>
I do not know what the syntax is to reference CSS properties in Java Script. What I want to do is to change the display property of the paragraph to hidden and the display property of the div to visible when the button is clicked.
Could someone please help me out with this?
question from:
https://stackoverflow.com/questions/65858304/how-do-i-use-the-css-display-property-on-clicking-a-button 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…