I want to make an input appear when I click on the label , when I click outside the input, that is, focus on it, I would like it to disappear.
HTML:
<form action="/" class="search">
<fieldset>
<label for="pesquisar">
<span>Buscar</span>
</label>
<input type="text" name="pesquisar">
<button type="submit" class="send-search"></button>
</fieldset>
</form>
JavaScript:
$(function() {
var label = $('.search label'),
input = $('.search label + input');
label.on('click', function() {
if (input.is(':focus')) {
input.css('display', 'none');
} else {
input.css({
'display': 'block'
}).focus();
}
});
}(jQuery));
What am I doing wrong?