parish parish - 21 days ago 9
HTML Question

How to find previous .multiselect class of li using active class

I have a list of select box suppose

.multiselect
is parent of all elements under it (i.e.
<li>
) when user select one option
.active
class is added to it.



$(".multiselect-container.dropdown-menu li").each(function(){
if($(this).hasClass("active")){
var TypeSubId = $(this).find("input").val();
var TypeID = $(this).prev(".multiselect").find("input").val();
}
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<ul class="multiselect-container dropdown-menu">
<li class="multiselect"><input type="checkbox" /></li>
<li><input type="checkbox" /></li>
<li><input type="checkbox" /></li>
<li><input type="checkbox" /></li>
<li class="active"><input type="checkbox" /></li>
<li><input type="checkbox" /></li>
<li><input type="checkbox" /></li>
<li class="multiselect"><input type="checkbox" /></li>
<li><input type="checkbox" /></li>
<li><input type="checkbox" /></li>
<li><input type="checkbox" /></li>
<li class="active"><input type="checkbox" /></li>
<li><input type="checkbox" /></li>
</ul>





So Now I need help in finding
TypeID
(value in JS code). I want to find value of
input checkbox
of first
.multiselect
above
.active
.

Answer

Use below code to find multi Select

  $(this).prevAll("li.multiselect:first").find("input").val()
Comments