[ Faulty code | Working code ]

Faulty

>Site Structure

Top Menu
  • Magic Mouse
    • News
    • ToDo
  • Articles
    • Android
      • Barcode
Code Faulty

List

<ul id="selectable"> <li class="ui-widget-content" id="Magic Mouse">Magic Mouse</li> <ul> <li class="ui-widget-content" id="News">News</li> <li class="ui-widget-content">ToDo</li> </ul> <li class="ui-widget-content">Articles</li> <ul> <li class="ui-widget-content">Android</li> <ul> <li class="ui-widget-content">Barcode</li> </ul> </ul>

JavaScript

<script type="text/javascript" language="javascript"> $(document).ready(function () { $(".ui-widget-content").click(function () { $(this).addClass("ui-selected").siblings().removeClass("ui-selected"); }); }); </script>

Working

Site Structure

Top Menu
  • Magic Mouse
    • News
    • ToDo
  • Articles
    • Android
      • Barcode
Code Working

List

<ul id="selectable"> <li class="ui-widget-content" id="Magic Mouse">Magic Mouse</li> <ul> <li class="ui-widget-content" id="News">News</li> <li class="ui-widget-content">ToDo</li> </ul> <li class="ui-widget-content">Articles</li> <ul> <li class="ui-widget-content">Android</li> <ul> <li class="ui-widget-content">Barcode</li> </ul> </ul>

JavaScript

<script type="text/javascript" language="javascript"> $(document).ready(function () { $(".ui-widget-content").click(function () { $('*').removeClass("ui-selected"); $(this).addClass("ui-selected"); }); }); </script>