checking if e.target is a child of a constant element
Hey guys , i am trying to basically write a Jquery programme that tells me when i click on an element weather that element is a child of another element(parent element , and in my programme , the parent element is a constant ). so heres what i got so far .
HTML code :
- <div>
- <p>lalalalalalalalalalal</p>
- <span>blaaaaaaaaaaaaaaaaa</span>
- </div>
now the Jquery :
- $(document).ready(function(){
-
- var str_dv = $('#la');
- $('p').on('click' , function(e){
-
- if (!str_dv.has(e.target).length) {
- console.log('has the element');
- }
-
- });
- });
Nothing happens :( when i clcik on p or span , i never get has the element , whats the problem .
also is
if (!str_dv.has(e.target).length)
the same as
if (str_dv.has(e.target).length > 0) ??
when i add the above condition instead i get a console.log when i click on the p but not when i click on the span . why so ?
I saw this on SO .
SO thread , but i really don't want to use the $.contains function .