I am trying to figure out how to make this one click event to take only one click, as it currently takes two. Before I had the on click event inline, but after reading here, I changed it to the code below but still did not work.
const input = document.getElementById("divinput");
input.addEventListener("click", myFunction2);
function myFunction2() {
var x = document.getElementById("recentsearch");
var element = document.getElementById("searchbox");
if (x.style.display === "none") {
x.style.display = "block";
element.style.borderRadius = "24px 24px 0px 0px";
} else {
x.style.display = "none";
element.style.borderRadius = "24px";
}
}
<div id="divinput" class="divinput">
<input type="text" class="textarea">
</div>
2
Answers
Thanks so much for your answer but I cannot make it to work. Nothing shows. I will keep trying, thanks!!!
Here is the logic with toggling elements in JS.
Input box click to show and again click same input box to hide the next below input box and it applies some styles to it.