I would like to change the width of the input field as soon as the cursor has been placed in the input field.
However, as soon as the user clicks on any body element that is not an input field, I would like the width to return to its original length. However, it seems that the program also changes the width back to its original length, even when the cursor is placed in the search field. How to select a body element that is not an input field.
<form class="search" action="/search">
{% if settings.search_option != "everything" %}
<input type="hidden" name="type" value="product" />
{% endif %}
<input type="text" name="q" class="search_box"
placeholder="{{ 'general.search.placeholder' | t }}"
value="{% if search and search.results.first.price %}{{ search.terms }}
{% endif %}"/>
</form>
var input = $(this).find('input[name="q"]');
input.bind('click', function(){
console.log("width changed");
$(this ).css({'width' : '600px'});
});
$("body:not(.search_box)").bind('click', function(){
$('input:text').css({'width' : 'inherit'});
});
$("body *:not(input:text)").bind('click', function(){
$('input:text').css({'width' : 'inherit'});
});
$('body').bind('click', function(){
$('.search-results').hide();
});
source
share