-2

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.

RocketFuel
  • 13
  • 3

3 Answers3

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';
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