I have a search form that I need that the input text begins hidden and with a button named search, the input appears and when the input is being shown, the button named search is converted to a close button to hide again the input text. My problem is that when the input text is hidden, the button moves to the center of my website. I need to stay in place next to the search box.
This is my code:
<div class="main-search-continer">
<form action="/content/testing.html">
<input class="inputSearch" size="41" maxlength="2048" name="q" value="">
<button type="button" class="js-btn-toggle_search">X Close</button>
</form>
<div class="clear"></div>
</div>
The JS:
$(document).on("click", "button.js-btn-toggle_search", function(){
var $btn = $(this)
$("input.inputSearch").toggle(0, '', function() {
if($(this).is(":visible")) {
$btn.text("X Close")
} else {
$btn.text("Search")
}
})
})
My CSS it's pretty simple:
input.inputSearch {
font-size: 30px;
width: 65%;
margin: 0 auto;
color: #939497;
font-weight: 300;
display:none;
}
div.main-search-continer {
width: 100%;
}
A fiddle to see the behavior.