Полагаю, что-то вроде этого и нужно:
//BASED OFF SO SINGULAR EXAMPLE
///1647204/jquery-v-fokuse-vvoda-formy-pokazat-div-skryt-div-na-razmytie-s-ogovorkoianswer-2427363
$('#search-markets').focus(function() {
$('div.select-filters.market').css('display', 'flex');
$(document).bind('focusin.select-filters.market click.select-filters.market',function(e) {
if ($(e.target).closest('.select-filters.market, #search-markets').length) return;
$(document).unbind('.select-filters.market');
$('div.select-filters.market').slideUp(300);
});
});
$('#search-symbols').focus(function() {
$('div.select-filters.symbol').css('display', 'flex');
$(document).bind('focusin.select-filters.symbol click.select-filters.symbol',function(e) {
if ($(e.target).closest('.select-filters.symbol, #search-symbols').length) return;
$(document).unbind('.select-filters.symbol');
$('div.select-filters.symbol').slideUp(300);
});
});
$('div.select-filters').hide();
#select-data-inputs {
background-color: #000;
}
.select-filters {
background-color: rgba(0, 0, 0, 0.8);
border-top: 2px solid #fff;
color: #fff;
}
#select-symbols {
background-color: rgba(1, 56, 89, 0.85);
}
#select-markets {
background-color: rgba(2, 104, 165, 0.85);
}
.filter-list li.list-inline-item {
width: 48%;
margin: 0;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
<div class="container-fluid">
<div class="row m-5 ">
<div class="col-12 text-center">
<h1>On form inputs focus, show div. hide div on blur for <span class="text-danger">multiple inputs</span> and hidden divs</h1>
<p class="lead"><i><a href="/1647204/jquery-v-fokuse-vvoda-formy-pokazat-div-skryt-div-na-razmytie-s-ogovorkoi" target="_blank">Based from SO sigular example</a></i></p>
</div>
</div>
<div class="row">
<!--TEXT FIELDS INPUT ROW-->
<!--TEXT FIELDS INPUT ROW-->
<div id="select-data-inputs" class="controls form-row p-3 w-100">
<div class="col-4">
<input type="text" id="search-markets" class="input form-control" placeholder="Search Markets">
</div>
<div class="col-4 offset-1">
<input type="text" id="search-symbols" class="input form-control" placeholder="Search Symbols">
</div>
</div>
</div>
<div id="main-display">
<!--HIDDEN DIV FOR FIRST TEXT FIELD-->
<!--HIDDEN DIV FOR FIRST TEXT FIELD-->
<div id="select-markets" class="row select-filters market p-4">
<div class="select-heading col-12 pl-2">
<h6 class="small-sub-heading">Select markets</h6>
</div>
<div class="col-4 pt-2 select-filter-items">
<ul class="filter-list list-unstyled pl-2">
<li class="list-inline-item">
<input class="form-check-input" type="checkbox" id="market-option-1" value="market-option-1">
<label class="form-check-label" for="market-option-1">Market Option 1</label>
</li>
<li class="list-inline-item">
<input class="form-check-input" type="checkbox" id="market-option-2" value="market-option-2">
<label class="form-check-label" for="market-option-2">Market Option 2</label>
</li>
<li class="list-inline-item">
<input class="form-check-input" type="checkbox" id="market-option-3" value="market-option-3">
<label class="form-check-label" for="market-option-3">Market-Option 3</label>
</li>
<li class="list-inline-item">
<input class="form-check-input" type="checkbox" id="market-option-4" value="market-option-4">
<label class="form-check-label" for="market-option-4">Market-Option 4</label>
</li>
</ul>
</div>
</div>
<!--HIDDEN DIV FOR SECOND TEXT FIELD-->
<!--HIDDEN DIV FOR SECOND TEXT FIELD-->
<div id="select-symbols" class="row select-filters symbol p-4">
<div class="select-heading col-4 offset-5 pl-2">
<h6 class="small-sub-heading">Select symbols</h6>
</div>
<div class="col-4 offset-5 pt-2 select-filter-items">
<ul class="filter-list list-unstyled pl-2">
<li class="list-inline-item">
<input class="form-check-input" type="checkbox" id="symbol-option-1" value="symbol-option-1">
<label class="form-check-label" for="symbol-option-1">Symbol Option 1</label>
</li>
<li class="list-inline-item">
<input class="form-check-input" type="checkbox" id="symbol-option-2" value="symbol-option-2">
<label class="form-check-label" for="symbol-option-2">Symbol Option 2</label>
</li>
<li class="list-inline-item">
<input class="form-check-input" type="checkbox" id="symbol-option-3" value="symbol-option-3">
<label class="form-check-label" for="symbol-option-3">Symbol Option 3</label>
</li>
<li class="list-inline-item">
<input class="form-check-input" type="checkbox" id="symbol-option-4" value="symbol-option-4">
<label class="form-check-label" for="symbol-option-4">Symbol Option 4</label>
</li>
</ul>
</div>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.bundle.min.js" integrity="sha384-pjaaA8dDz/5BgdFUPX6M/9SUZv4d12SUPF0axWc+VRZkx5xU3daN+lYb49+Ax+Tl" crossorigin="anonymous"></script>
Вам нужно разделить класс между символами и рынками (.select-filters
).Обратите внимание, что я использую add select-filters
market
для рынка и select-filters
symbol
для символа.
Для разделения фокуса вам нужно использоватьуказанная функция, например, div.select-filters.market
для рынка и div.select-filters.symbol
для символа:
$('#search-markets').focus(function() {
$('div.select-filters.market').css('display', 'flex');
$(document).bind('focusin.select-filters.market click.select-filters.market',function(e) {
if ($(e.target).closest('.select-filters.market, #search-markets').length) return;
$(document).unbind('.select-filters.market');
$('div.select-filters.market').slideUp(300);
});
});
$('#search-symbols').focus(function() {
$('div.select-filters.symbol').css('display', 'flex');
$(document).bind('focusin.select-filters.symbol click.select-filters.symbol',function(e) {
if ($(e.target).closest('.select-filters.symbol, #search-symbols').length) return;
$(document).unbind('.select-filters.symbol');
$('div.select-filters.symbol').slideUp(300);
});
});
$('div.select-filters').hide();