dimanche 12 juillet 2015

How to open dropdown on click of button?

I have one dropdown on my html page and one button on that page. now I want to do something like thst when user click on button then dropdown will open. I tried this jquery code

$('.add_award_ready').click(function(){
  student_id = $(this).attr('id');
  var element = $('#add_award_form_' + student_id + ' select')[0], worked = false;
    if (document.createEvent) {
        var e = document.createEvent("MouseEvents");
        e.initMouseEvent("mousedown", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
        worked = element.dispatchEvent(e);
    } 
}

but this will works only once.If I clicked once again on button then dropdown does not opens. whats' going wrong?

thanks in advance.

Aucun commentaire:

Enregistrer un commentaire