javascript - Jquery - selecting an element and anything inside it -
i have click event , if statement within shown below.
if (!$(e.target).is("textarea.textobject, div.texteditor")) { // stuff }
it works problem div shown below. when click on either span or table inside div doesn't work. have tried (div.texteditor > *) doesn't work.
<div class="texteditor"> <span>1</span> <table> <tr><td></td></tr> </table> </div>
so want able select div.texteditor , encompass inside it. know solution this? i'm sure i'm missing something..
if event handler on <div>
itself, use this
instead of e.target
(which may child), this:
if (!$(this).is("textarea.textobject, div.texteditor")) { // stuff }
...if instead want check if target anywhere inside 1 of 2 selector types, use .closest()
, .length
, this:
if ($(e.target).closest("textarea.textobject, div.texteditor").length == 0) { // stuff }
since .closest()
works on current elements and parents, it's pretty handy here.
Comments
Post a Comment