Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
10
rated 0 times [  17] [ 7]  / answers: 1 / hits: 30481  / 13 Years ago, thu, june 30, 2011, 12:00:00

I wonder how I in the best way can see if a container div contains a child element. I have a click event that fires on a child of either div id=unread or div id=read. I want to check where this child is.



Something like this is what I'm thinking:



if ($(#unread).find($(this)))
alert(unread);
else
alert(read);


Edit:
$(this) is a descendants two levels from #unread or #read.



Regards


More From » jquery

 Answers
8

Make use of : .children()



if( $(#unread).children().length > 0)
alert(unread);
else
alert(read);


EDIT



if($(event.target).closest('#unread').length > 0)
alert('unread');
else
alert('read');

[#91430] Tuesday, June 28, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jaredsages

Total Points: 273
Total Questions: 97
Total Answers: 105

Location: French Southern and Antarctic Lands
Member since Fri, Jan 6, 2023
1 Year ago
jaredsages questions
;