michaelmcgurk michaelmcgurk - 1 month ago 8
jQuery Question

Nesting select menus inside div breaks jQuery menu

I am developing a multi chained dropdown system using jQuery.

My demo here works great: https://jsfiddle.net/m27pnyo3/

However, when I want to nest each select menu in a

<div>
element, I am having problems. I believe these problems stem from my use of
$(this).parent())
.

See this revised Demo with
<div>
elements around each
<select>
- you can see it breaks :(

Can someone explain what I change in my jQuery below to resolve this?

$(function() {

$(".series").each(function() {
$(this).chained($(".mark", $(this).parent()));
});
$(".model").each(function() {
$(this).chained($(".series", $(this).parent()));
});
$(".engine").each(function() {
$(this).chained([
$(".series", $(this).parent()),
$(".model", $(this).parent())
]);
});

});

Answer

Just add another .parent()

this.parent().parent()

Now you have added a div as parent and this should get it to original destination.

Comments