Search code examples
javascriptjquerybootstrap-multiselect

jQuery select an element within a selected element


I am using the multiselect plugin for bootstrap. What the plugin does is take a dropdown(select) and adds checkboxes on every option so you can select more than one option in a select.

The thing I need to do in order to enable the multiselect on a select is just $("#selectThis").multiselect().end()

This is how a select with multiselect looks like in html.

select.hidden
.btn-group > button + (ul.multiselect-container > li, li , li)

I can add an onChange function like this.

        $('#add-workout').find('[name="class1[]"],[name="movement1[]"]')
                .multiselect({onChange:function(element){
                    console.log($(this))
                }})
                .end()
        })

I need to select the .multiselect-container of the changed element but $(this) refers to the multiselect object.


Solution

  • You should be able to get the parent by calling $(element).parent().parent().siblings(".btn-group").find(".multiselect-container") instead of $(this), after all you are passing the current selected element as a function parameter ;)