3
I want to make an input appear when I click on label, when I click out of the input, ie take the focus of such, 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 I’m doing wrong?
Thank you very much! I made just a few adjustments but it worked perfectly :D
– João Paulo Vieira da Silva