I want to hide my div after click on a search icon, it isn’t a button so I don’t really know how to do it. I want to hide this text "
Simply click on the … and type the name of where you would like to visit
" by clicking on the div class="search-icon".
<div id="intro">
<p>Simply click on the <i class="fas fa-search"></i> and type the name of where you would like
to visit</p>
<div class="search-box">
<input id="searchBox" type="text" placeholder="Search your location">
<div class="search-icon">
<i class="fas fa-search"></i>
</div>
<div class="cancel-icon">
<i class="fas fa-times"></i>
</div>
<div class="search-data"></div>
</div>
</div>
I’ve tried few js code but because it isn’t a button I am not sure hot it should work.
5
Answers
To do this you need to use the click event https://developer.mozilla.org/en-US/docs/Web/API/Element/click_event
the best way to do his is to add an id on your element you want clickable then here’s the code :
Use Collapsible from Bootstrap for easy and Fast Solution
There is a misunderstanding in your question.
If you want to hide any element, you can select it by its ID or class name. Here, I used the class name. Since there are two elements with the same class name, I manually selected the first one.
Here is the code:
First you need to give
<p>
and second search icon a clear classes, so you can select them in the dom:then for the JS part first you need to select that paragraph and the second search icon:
and for actually hiding the text you need to add a css class: