I'm trying to get a font awesome icon to appear once input has been detected, the font awesome search icon must be invisible until user start typing something, but this icon keeps blinking and for some reason jumping altogether with an input box. It must only appear after users input.
Here is codepen: https://codepen.io/ekilja01/pen/pRerpb
$(document).ready(function() {
var cursorBlink = setInterval(function blink() {
$(".searchRequest").toggleClass("hidden");
}, 500);
$(".searchRequest").on("click", function() {
clearInterval(cursorBlink);
})
var icon = "<i class='fa fa-search fa-2x'></i>";
if ($(".searchRequest").length > 0) {
console.log("Not empty anymore");
$(".searchIcon").append(icon);
}
});
body {
background: #7b4397;
/* fallback for old browsers */
background: -webkit-linear-gradient(to left, #7b4397, #dc2430);
/* Chrome 10-25, Safari 5.1-6 */
background: linear-gradient(to left, #7b4397, #dc2430);
/* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */
}
.headertext {
margin-top: 100px;
margin-left: 25%;
margin-right: 25%;
color: white;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 60px;
font-weight: lighter;
}
.searchRequest {
margin-top: 5px;
margin-left: 25%;
margin-right: 25%;
border: 0;
outline: none;
box-shadow: none;
background-color: inherit;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 40px;
color: white;
font-weight: lighter;
opacity: 0.5;
box-width: 50px;
box-height: 5px:
}
.fa-search {
color: white;
font-weight: lighter;
margin-top: 2px;
margin-left: 40%;
margin-right: 25%
}
.hidden {
visibility: hidden;
}
.i {
color: white;
float: right;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://use.fontawesome.com/43f8201759.js">
</script>
<h2 class="headertext">WIKIPEDIA <br> VIEWER</h2>
<div class="row">
<div class="col-10-md">
<input class="searchRequest" id="cursor" type="text" placeholder="_"></input>
</div>
<div class="searchIcon col--md"></div>
</div>
What am I doing wrong? Please help.