Figuring out how to use a conditional statement if children exist...
So I'm new to jQuery and loving it! I just got stuck on a problem that I'm not sure how to work around. I'm trying to add a class to a li item in a navigation if it has child list items underneath it. For example, if I have this situation:
- <ul>
- <li><a href="#">List Item 1</a>
- <ul>
- <li><a href="#">Sub List Item 1</a></li>
- </ul>
- </li>
- <li><a href="#">List Item 2</a></li>
- </ul>
So in this situation, since List Item 1 has list items underneath it (children), I want to be able to append a class to it like so:
- <li class="foo"><a href="#">List Item #1</a></li>
I've attempted this, but it appends class to all the list items...even those that have no "2nd Level" list items:
- if ($('#headerNav ul li a').is(':parent')) {
$('#headerNav ul li').append('class="standalone"');
}
Any insight for a fledgling beginner would be much appreciated. Thanks!