I'm implementing a function where a div should increase in height and opacity when clicked, and then revert back to its original state when clicked again. I used the toggle function for this purpose, but the issue is that the button disappears when the page loads
$(document).ready(function() {
$('#cm_now').toggle(function() {
$('.search_bx_ar').css({
'opacity': '1'
});
$('.search_bx_ar').css({
'height': '40px'
});
});
});
.search_bx_ar {
position: relative;
margin: 0 0 10px 0;
width: 100%;
opacity: 0;
height: 0px;
transition: ease-in-out all .5s;
-webkit-transition: ease-in-out all .5s;
-moz-transition: ease-in-out all .5s;
}
.compare_sr_btn {
float: right;
width: 25%;
padding-left: 15px;
margin: 15px 0 10px 0;
}
.compare_sr_btn>#cm_now {
background-color: #2b7f7f;
color: #fff;
border: none;
height: 40px;
line-height: 40px;
width: 100%;
font-size: 12px;
text-transform: uppercase;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="compare_sr_btn">
<input type="button" id="cm_now" value="Compare Now" />
</div>
<div class="search_bx_ar">
<input class="form-control top_search" id="data_mid" autocomplete="off" onkeyup="autocompl();" type="text" placeholder="Search">
</div>