I have a bootstrap dropdown menu. I want it to be kept open when I click inside it, but closed when clicking the dropdown toggle button or outside of the menu.

It seems like the dropdown does not close when I type something in the input but it closes when I click anywhere else inside the dropdown.

Q: How can I avoid this by using jQuery?

Below is my HTML:

<div id="navbar">
  <nav class="navbar navbar-default navbar-static-top" role="navigation">
    <div class="collapse navbar-collapse" id="navbar-collapse-1">
      <ul class="nav navbar-nav">
        <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown">MENU</a> 
          <div class="dropdown-menu">
            <p>HELLO</p>
            <input>
          </div>
        </li>
      </ul>
    </div>
  </nav>
</div>

Demo in Bootply

From the question Avoid dropdown menu close on click inside, you can simply stop propagation from inside the dropdown like this:

<!-- language: lang-js -->
$(document).on('click', '.allow-focus .dropdown-menu', function (e) {
  e.stopPropagation();
});

Demo in Stack Snipets

<!-- begin snippet: js hide: true console: true babel: false --> <!-- language: lang-js -->
$(document).on('click', '.allow-focus .dropdown-menu', function (e) {
  e.stopPropagation();
});
<!-- language: lang-html -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.js"></script>


<div class="dropdown allow-focus">
  <button id="dropdownLabel" type="button" class="btn btn-default"
          data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
    Dropdown trigger
    <span class="caret"></span>
  </button>
  <div class="dropdown-menu panel" aria-labelledby="dropdownLabel">
    <div class="col-xs-12">
      What's Your Name?
      <input type="text" placeholder="Name" class="form-control" />
    </div>
  </div>
</div>
<!-- end snippet -->

NOTE: To solve the opposite problem (of keeping open until clicked), you can refer to:

Keep Bootstrap Dropdown Open When Clicked Off