javascript - How to onclick outside an input element which is inside a div? -
It is probably easy, but the way I click outside the text box to make some alert in JavaScript, it I can not think of anything to find when I click to do nothing inside the text. The input text is inside the div element.
So, suppose my html is like bellow:
How to change it?
Thank you very much!
You shoud using this condition.
It is often useful to compare event.target to determine whether the event is being triggered by event bubbling. is. Use this in your click function like this and see it in action:
$ ('. Divver'). ('Click', function (e) {if (e.target! == this) return; thefunc ();}); Var thefunc = function myfunc () {warning ('OK'); } .divover {padding: 20px; Background: yellow; } Period {background: blue; White color; Padding: 8px; } & lt; Script src = "https://ajax.googleapis.com/ajax/libs/JQuery/1.1.1/jquery.min.js" & gt; & Lt; / Script & gt; & Lt; Div class = 'divover' & gt; Somelabel: & lt; Span & gt; Input type = "text" class = "like" name = "first name" & gt; & Lt; / Span & gt; & Lt; / Div & gt;
Comments
Post a Comment