I created a responsive search button that will open a form once a user click on it but in mobile devices the form should appear without the need of the user to click on any button.
I was able do it by adding a class so on first click on the button the menu open and on second click it will submit the input.
The obstacle now is to add the active class just in mobile. What is the best way to do it? If it detected by userAgent that are mobile devices that has a larger screens (like tablets).
I know that there is option to do it by detecting the screen size of the device, the question what will be more efficient for my purpose or if there is any other way that I can achieve this thing.
Here is the relevant part of the code:
$(document).on('click', '.navbar-collapse form[role="search"]:not(.active) button[type="submit"]', function(event) {
event.preventDefault();
var $form = $(this).closest('form'),
$input = $form.find('input');
$form.addClass('active');
$input.focus();
});