javascript - Exclude elements from click event handler (jquery) -


i have defined event handler elements on page.

var selector = "div, select, input, button"; $(selector).on('click', function (e) {     //deactivate function of elements , prevent propagation     e.preventdefault();     e.stoppropagation();     //...     //dialog loaded , created here     //e.g. $(body).append('<see-dialog-html-from-below>');     //...     alert('selector click'); } 

i add (and remove) dialog dom @ runtime (one dialog @ time). simplified dialog 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 cancel , save buttons when create dialog.

the problem select box. triggers first click event defined above.

how can exclude elements in dialog box being included in first event handler?

if clicking select triggers alert, in first event handler, dialog exists in page time execute $(selector).on('click', ...). in case can exclude elements selector not.

$(selector).not('#dialog').on('click', ...) 

this bind click handler elements matched selector excluding elements matched in not. if have several dialogs consider using css class ui-dialog , using not('.ui-dialog').

edit: note if dialog placed inside div , not stop propagation of custom events click in popup bubble , trigger handler in parent div. ensure use e.stoppropagation(); when adding handlers dialog actions.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -