Wanted to try replicating Google's search textbox in a simple way. This is the whole HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Search</title>
<link rel="stylesheet" href="styles.css">
<script type="text/javascript" src="extJs.js"></script>
</head>
<body>
<div id="searchform">
<div>
<img class="gImage" src="https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png" alt="Google">
</div>
<div>
<form action="https://google.com/search" method="GET" role="search" id="gForm">
<div id="sBar">
<span class="material-icons" role="button"></span>
<input type="text" value="" name="q" onchange="cursorDisplay()" id="forClear">
<div id="xbutton">
<span class="ExCKkf z1asCe rzyADb" jsname="itVqKe" role="button" tabindex="0" aria-label="Clear" onclick="clearText()">
<svg focusable="false"
xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" data-iml="1633938141181">
<path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"></path>
</svg>
</span>
</div>
</div>
<input type="submit" name="bntK" class="sButton" value="Google Search" aria-label="Google Search">
<input type="submit" name="btnI" class="sButton" value="I'm Feeling Lucky" aria-label="I'm Feeling Lucky">
</form>
</div>
</div>
<script type="text/javascript">cursorDisplay();</script>
<script type="text/javascript">clearText();</script>
</body>
</html>
Focus on input and <div id="xButton"..> part.
Then this is my extJs.js:
function cursorDisplay() {
var x = document.getElementById("xbutton");
if(window.getComputedStyle(x).style.display === "none") {
x.style.display = "inline-block";
}
// document.getElementById("xbutton").style.display = "inline-block";
}
function clearText() {
document.getElementById("gForm").reset();
}
CSS:
.ExCKkf {
visibility: visible;
margin-right: 12px;
height: 100%;
color: #70757a;
vertical-align: middle;
outline: none;
}
#xbutton {
display: none;
}
Anyone have an idea where my oninput or JS became wrong? I prefer no events since i just wanted a simple approach.