1

I have developed multi column dropdown using div and table.

How to hide dropdown when click on html body or any other control.Any suggestions

<input type="text" id="mulitcolumn">
 <div id="myDropdownGrid" class="dropdownGrid" style="overflow:hidden;overflow-y:auto;  max-height: 400px;border-right:1px solid rgb(51, 102, 153)">
                    <table class="grid">                      
                       @foreach (var item in (IEnumerable<SelectListItem>)ViewBag.List)
                       {
                         <tr>
                            <td style="display:none">@item.Value</td>
                            <td>@(item.Text.Substring(1, item.Text.IndexOf(']') - 1))</td>
                            <td>@(item.Text.Substring(item.Text.IndexOf("] - ") + 3, item.Text.Length  - (item.Text.IndexOf("] - ") + 3)))</td>
                         </tr>
                       }
                    </table>
                </div>

 $('#myDropdownGrid table tr').click(function () 
    {
        var tableData = $(this).children("td").map(function () {
            return $(this).text();
        }).get();

        $('#myDropdownGrid table').toggle();
    });
HaveNoDisplayName
  • 8,291
  • 106
  • 37
  • 47
user334223
  • 301
  • 2
  • 8
  • 17
  • 1
    Possible duplicate of [jQuery click anywhere in the page except on 1 div](http://stackoverflow.com/questions/12661797/jquery-click-anywhere-in-the-page-except-on-1-div) – madalinivascu Nov 03 '15 at 09:15

1 Answers1

1

Try:

  $('.dropdownGrid').on('click',function() {
              $(this).addClass('activ');
$(this).find('.grid').show();
            });
            $('body').click(function(evt){   
               console.log(evt.target)
                   if(evt.target.class == "activ" || $(evt.target).closest('.activ').length) {
                      return;  }
                else {
                     $(this).removeClass('activ');
                      $(this).find('.grid').hide()

                }

            });
madalinivascu
  • 32,064
  • 4
  • 39
  • 55