how to filter un-ordered list using jquery or javascript

Posted on 2012-08-23
Last Modified: 2012-09-10
on this template

if you click on sub menu, ALL, Design, Graphic etc the irrelevant div's become invisible. I am creating a similar layout using list li elements. How can we hide a li using javascript or Jquery

Question by:mmalik15
    LVL 9

    Accepted Solution

    This should do what you need...

    <ul id="dynamicUL">
    <li class="typeA">One</li>
    <li class="typeB">Two</li>
    <li class="typeA">Three</li>
    <a href="#" id="Link1">Hide Type A</a><br>
    <a href="#" id="Link2">Hide Type B</a><br>
    <a href="#" id="Link3">Show All</a><br>
    <a href="#" id="Link4">Only Show Type B</a>¿

    Open in new window

    $('#Link1').click(function() {
    $('#Link2').click(function() {
    $('#Link3').click(function() {
        $('#dynamicUL li').show();
    $('#Link4').click(function() {

    Open in new window

    LVL 49

    Expert Comment

    by:Julian Hansen
    This is the essence of it.
    <!doctype html>
    <script src=""></script>
    <script type="text/javascript">
    $(function() {
      $('button.hidebutton').click(function() {
         $('li.' + $(this).attr('id')).hide();
    <style type="text/css">
      <li class="firstbutton">First of first</li>
      <li class="firstbutton">Second of first</li>
      <li class="secondbutton">First of second</li>
      <li class="secondbutton">Second of second</li>
    <button id="firstbutton" class="hidebutton">First Button</button>
    <button id="secondbutton" class="hidebutton">Second Button</button>

    Open in new window

    LVL 9

    Expert Comment

    (in my post, ignore the weird question marks... copy/paste seems to have grabbed something that wasn't visible on the page)

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
    Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now