Есть связаныне списки, которые я хочу перенести в итоговый проект на сайт на движке
wordpress. На тестовом работает хорошо, а вот в рабочем запись с
:nth-child(2) -
li.sf-field-taxonomy-ad_cat:nth-child(2) select
не воспринимает. Если еще для
parent обхожусь так
var parent = document.getElementsByClassName("sf-field-taxonomy-ad_cat")[0].getElementsByClassName("sf-input-select")[0]
то как быть с
$children = $('li:nth-child(2) select');
?
Код
jQuery.noConflict();
(function($) {
$(window).load(function() {
var parent = 'li:nth-child(1) select',
$children = $('li:nth-child(2) select');
$(document).on('change', parent, function() {
var $this = $(this),
value = $this.val(),
start = $children.find('option[value="' + value + '"]').index(),
$childrens = $children.find('option').slice(start + 1);
$children.find('option').hide();
$childrens.each(function() {
if ($(this).is('.sf-level-0')) {
return false;
}
$(this).show();
});
});
$(parent).trigger('change');
});
})(jQuery);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul>
<li class="sf-field-taxonomy-ad_cat" data-sf-field-name="_sft_ad_cat" data-sf-field-type="taxonomy" data-sf-field-input-type="select" data-sf-combobox="1" data-sf-term-rewrite="["http:\/\/site.com\/ad-category\/[0]\/"]">
<label>
<select data-combobox="1" name="_sft_ad_cat[]" class="sf-input-select" title="">
<option class="sf-level-0 sf-item-0" data-sf-count="0" data-sf-depth="0" value="">марка а/м</option>
<option class="sf-level-0 sf-item-32" data-sf-count="1" data-sf-depth="0" value="alfa-romeo">Alfa Romeo</option>
<option class="sf-level-0 sf-item-19 sf-option-active" selected="selected" data-sf-count="12" data-sf-depth="0" value="audi">Audi</option>
</select>
</label>
</li>
<li class="sf-field-taxonomy-ad_cat" data-sf-field-name="_sft_ad_cat" data-sf-field-type="taxonomy" data-sf-field-input-type="select" data-sf-combobox="1" data-sf-term-rewrite="["http:\/\/site.com\/ad-category\/[0]\/"]">
<label>
<select data-combobox="1" name="_sft_ad_cat[]" class="sf-input-select" title="">
<option class="sf-level-0 sf-item-0 sf-option-active" selected="selected" data-sf-count="0" data-sf-depth="0" value="">марка а/м</option>
<option class="sf-level-0 sf-item-32" data-sf-count="1" data-sf-depth="0" value="alfa-romeo">Alfa Romeo</option>
<option class="sf-level-1 sf-item-59" data-sf-count="1" data-sf-depth="1" value="156"> 156</option>
<option class="sf-level-0 sf-item-19" data-sf-count="10" data-sf-depth="0" value="audi">Audi</option>
<option class="sf-level-1 sf-item-60" data-sf-count="1" data-sf-depth="1" value="a6c5"> A6C5</option>
<option class="sf-level-1 sf-item-61" data-sf-count="1" data-sf-depth="1" value="a4"> A4</option>
<option class="sf-level-1 sf-item-62" data-sf-count="1" data-sf-depth="1" value="a6"> A6</option>
</select>
</label>
</li>
</ul>