I have defined an event handler for some elements on the page.
var selector = "div, select, input, button";
$(selector).on('click', function (e) {
//deactivate function of the elements and prevent propagation
e.preventDefault();
e.stopPropagation();
//...
//dialog is loaded and created here
//e.g. $(body).append('<see-dialog-html-from-below>');
//...
alert('selector click');
}
I then add (and remove) a dialog to the DOM at runtime (one dialog at a time). A simplified dialog could look like this:
<div id="dialog" class="ui vertical menu">
<div class="item">
<label for="constraints">Constraints:</label>
<select id="constraints" name="constraints">
<option value="0">option 0</option>
<option value="1">option 1</option>
<option value="2">option 2</option>
<option value="3">option 3</option>
</select>
</div>
<div class="item clearfix">
<div class="ui buttons">
<div id="save_button" class="ui green button">Save</div>
<div class="or"></div>
<div id="cancel_button" class="closebutton ui button">Cancel</div>
</div>
</div>
</div>
I bind more click actions to the cancel and save buttons when I create the dialog.
The problem is the select box. It triggers the first click event that I defined above.
How can I exclude all elements in the dialog box from being included in the first event handler?
selectjust remove it from theselectorvariable.#dialogor possibly depending on your markup use>to limit the selector to direct children of some element (hard to say without seeing the all markup) Or something like*:not(#dialog) selectand so on as selectors.if (e.target.hasClass())or something alike