I want to hide a p
tag using plain JavaScript
. I don't want to use React. I am new to HTML and Javascript. Please excuse if this question doesn't make sense.
Asked
Active
Viewed 42 times
-2

RocketFuel
- 13
- 3
-
1Set the `display` style to `none`. Or give it a class whose `CSS` has `display: none;` style. – Barmar Nov 17 '21 at 16:52
-
1hide it when a button is clicked, when x equals 2, when? have you tried anything? – depperm Nov 17 '21 at 16:52
3 Answers
0
You can hide the p element by setting its display property to none or visibility property to hidden. If you want to completely hide it you can do the following.
document.querySelector('p').style.display = 'none';

Juniad Ali
- 3
- 3
0
You have to select your html tag in javascript, you can do that by setting a class or an id to your p tag and then set it to display: none;
For example :
<p id="text">My text to hide</p>
let myTextToHide = document.getElementById("text").style.display = 'none';

Kayoshi
- 36
- 7
-1
You can hide elements using css. See below:-
setTimeout(() => {
document.getElementById("p-tag").style.display = "none"
}, 1000)
<p id="p-tag">Hello</p>

samcodee
- 103
- 13