html - Alert the count of <li>s in an adjacent <div> to a button being clicked -


this first post website has been useful here goes... oh , im beginner ;-)

  1. i have button (a div class) , div inside element side side.
  2. inside second div have ul , number of li's dynamically change.
  3. when button clicked, need count of li's in div next button only
  4. the various alerts i've used wrong , return count of li's inside 'hidden-row-content' not adjacent 'hidden-row-content' div returns 4 instead of 2 :-(

html code:

<td>     <div class="show-hidden-row"><!-- --></div>     <div class="hidden-row-content">         <ul>             <li>item</li>             <li>item</li>         </ul>     </div>     <em>persons name</em> </td> <td>     <div class="show-hidden-row"><!-- --></div>     <div class="hidden-row-content">         <ul>             <li>item</li>             <li>item</li>         </ul>     </div>     <em>persons name</em> </td> 

jquery code:

non of these right 1 close enough spot problem

$(".show-hidden-row").click (function() {      window.alert($(this,".hidden-row-content").children("ul").length);     window.alert($(this).find('.hidden-row-content ul li').length);     window.alert($('.hidden-row-content ul li').length);     window.alert($(this).next('.hidden-row-content').length);    } ); 

this finds next <div>, , searches <li>s:

$(this).next('.hidden-row-content').find('li').length 

working example: http://jsbin.com/orudu


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -