[jQuery] Re: Do something, ONLY if parent has children

2008-05-30 Thread hubbs
Sorry for not being clear. I would like to hide H3 when next element does not have class 'calendarEvent' (Meaning, there would be another H3, if there was not a div with class 'calendarEvent' E.g.: h3Text/h3 h3Text/h3 h3Text/h3 h3Text/h3 h3Text/h3 div class=calendarEventtext/div h3Text/h3 div

[jQuery] Re: Do something, ONLY if parent has children

2008-05-30 Thread Giuliano Marcangelo
$('h3').hide(); $('.calendarEvent').prev('h3').show(); 2008/5/30 hubbs [EMAIL PROTECTED]: Sorry for not being clear. I would like to hide H3 when next element does not have class 'calendarEvent' (Meaning, there would be another H3, if there was not a div with class 'calendarEvent' E.g.:

[jQuery] Re: Do something, ONLY if parent has children

2008-05-29 Thread Wizzud
Can you be a bit more explicit about what it is that you want to do? eg. hide H1 where next element does not have class 'fred' or hide DIV, H1 and H6 where first child is not (DIV.dynamo) or hide P, H1 thru H6 where next element is not (P.kiev) or is (P.kiev having a child of A.hideme)

[jQuery] Re: Do something, ONLY if parent has children

2008-05-28 Thread Michael Geary
I would do it by checking the DOM directly, just because it's reasonably straightforward and very efficient: var $main = $('#main'); if( $main[0] $main[0].firstChild ) $main.hide(); -Mike I am wondering how I could check if a parent element has children, and it it does not, I would

[jQuery] Re: Do something, ONLY if parent has children

2008-05-28 Thread Hamish Campbell
You can do it with selectors: $('#main:not(:has(*))').hide(); Ie - 'select the element with the id main that does _not_ contain any other element'. Note that this is different from $('#main:empty') which includes text nodes. On May 29, 12:10 pm, Michael Geary [EMAIL PROTECTED] wrote: I would

[jQuery] Re: Do something, ONLY if parent has children

2008-05-28 Thread hubbs
Thanks Mike, Could you explain your if statement for me, what does the do? I am still learning js and jQuery. :) On May 28, 5:10 pm, Michael Geary [EMAIL PROTECTED] wrote: I would do it by checking the DOM directly, just because it's reasonably straightforward and very efficient:     var

[jQuery] Re: Do something, ONLY if parent has children

2008-05-28 Thread hubbs
Hey guys, I realized that I misstated my problem. I realized that the item I want to check for is NOT a child, but the element that comes AFTER a specific element. So, I have a list of specific elements, and if an element with a specific class does not come after the first element, hide the

[jQuery] Re: Do something, ONLY if parent has children

2008-05-28 Thread Hamish Campbell
Don't forget to check the jQuery documentation: http://docs.jquery.com/ The selector you want is 'prev + next': http://docs.jquery.com/Selectors/next#prevnext Eg, if I wanted to highlight in blue every paragraph object that comes after a h1 heading: $('h1 + p').css('color', 'blue'); On May

[jQuery] Re: Do something, ONLY if parent has children

2008-05-28 Thread hubbs
Thank you. So, if I wanted to check to see if there even were any p tags after an h1 tag, and I wanted to hide the h1 tag, I would do the following? $('h1 + p:not(:has(*))').hide(); On May 28, 7:22 pm, Hamish Campbell [EMAIL PROTECTED] wrote: Don't forget to check the jQuery