Johansrk
Johansrk

Reputation: 5250

jquery dropdown close with other element

I am using this plugin http://vst.mn/selectordie/ for making dropdowns. But I can't figure out, how I can make another element close the menu.

I have made a fiddle http://jsfiddle.net/Lgq1grrm/1/

$("select").selectOrDie();

$(".closeSelect").on('click', function(e) {
    e.stopPropagation();
});

can someone help, please

Upvotes: 1

Views: 378

Answers (2)

A. Wolff
A. Wolff

Reputation: 74410

Just remove specific classes:

$(function(){
    $("select").selectOrDie();

    $(".closeSelect").on('click', function(e) {
        e.stopPropagation();
        $(".sod_select").removeClass('focus open');
    });
});

-DEMO-

Upvotes: 0

Ionică Bizău
Ionică Bizău

Reputation: 113485

I browsed the code a little bit, but it looks like this plugin doesn't have such a method.

However, we can hack it, following what happens on the click on an option:

$("select").selectOrDie();

$(".closeSelect").on('click', function() {
    $(".selected, .sod_placeholder", "select").removeClass("selected sod_placeholder");
    $("select").removeClass("open");
});

JSFIDDLE

Upvotes: 3

Related Questions