In attempting to modify a script of a menu, that I wanted to add the ability to have sub menus, I first wanted to find out if an ordered list element, contained a secondary unordered list and what their names are so I could out put the items to the console.
Here is the test list:
- <div class="nav-wrap">
- <ul class="group" id="example-one">
- <li class="current_page_item"><a href="#">Home</a></li>
- <li><a href="#">Buy Tickets</a></li>
- <li><a href="#">Group Sales</a></li>
- <li>
- <a href="#">Reviews</a>
- <ul>
- <li>
- <a href="#">One</a>
- <a href="#">Two</a>
- <a href="#">Three</a>
- </li>
- </ul>
- </li>
- </ul>
- </div>
And here is the jQuery that I tried in several variations to ouput to the console. I am not figuring out how to point correctly to the children elements and how to print to the console. Hope someone can help. Thanks!
- $("#example-one li a").hover(function() {
- $el = $(this);
- leftPos = $el.position().left;
- newWidth = $el.parent().width();
- if($el.length > 0 ){
- console.log($el.length);
- var myContent = $el.children('li');
- console.log(myContent);
- }
- $($el + '>').each(function(idx, element){
- console.log(
- 'Element ' + idx +
- 'has the following html: ' +
- $(element).html()
- );
- });