tags:

views:

64

answers:

2

I use the following code to find a particular table, hide it then show it on click:

$(function() {
  $('.Nav table .navitem').hide();
  $('.Nav table.navheader').click(function() {
    $(this).parent().parent().next().find(".navitem").slideToggle('100');
  });
});

Here is the HTML Output:

<div class="Nav">

<table cellpadding="0" cellspacing="0" border="0">
  <tr>
    <td>
      <table class="navheader" cellpadding="0" cellspacing="0" border="0" width="100%">
       <tr>
        <td style="width:100%;"><a navheader" href="#">Header</a></td>
       </tr>
      </table>
    </td>
  </tr>
  <tr>
    <td>
      <table border="0" cellpadding="0" cellspacing="0" width="100%" class="navSubMenu">
       <tr>
        <td>
         <table class="ms-navitem" cellpadding="0" cellspacing="0" border="0" width="100%">
          <tr>
           <td style="width:100%;"><a class=" ms-navitem" href="#" style="border-style:none;font-size:1em;">Item</a></td>
          </tr>
         </table>
        </td>
       </tr>
      </table>

A basic accordion navigation hacked together from a table, however some of the .havheader's do not have .navitem's so I dont want these to be clickable.

How best can i achieve this?

+2  A: 

Change this selector:

$('.Nav table.navheader')

to this:

$('.Nav table.navheader:has(.navitem)')
cpharmston
I've change my post to show HTML out put as your suggestion does not work, but seems to come very close.
danit
This doesnt work because .navitem is outside of .navheader so the table.navheader does not have an element of .navitem..navitem is a table outside.
danit
A: 

If you just want accordion, maybe it is better to use jQuery UI instead...

Aaron Qian
I would if that were possible however the HTML cannot be altered, see comments above in original post.
danit