[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 291
  • Last Modified:

how to filter un-ordered list using jquery or javascript

on this template

http://xiaothemes.staging.wpengine.com/architect/works/ 

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

thanks
0
mmalik15
Asked:
mmalik15
  • 2
1 Solution
 
WebDevEMCommented:
This should do what you need...

HTML:
<ul id="dynamicUL">
<li class="typeA">One</li>
<li class="typeB">Two</li>
<li class="typeA">Three</li>
</ul>
<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

Javascript
$('#Link1').click(function() {
    $('.typeA').hide();
});
    
$('#Link2').click(function() {
    $('.typeB').hide();
});

$('#Link3').click(function() {
    $('#dynamicUL li').show();
});
    
$('#Link4').click(function() {
    $('.typeA').hide();
    $('.typeB').show();
});
¿

Open in new window

0
 
Julian HansenCommented:
This is the essence of it.
<!doctype html>
<html>
<head>
<title>Test</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
  $('button.hidebutton').click(function() {
     $('li').show();
     $('li.' + $(this).attr('id')).hide();
  });
});
</script>
<style type="text/css">
</style>
</head>
<body>
<ul>
  <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>
</ul>
<button id="firstbutton" class="hidebutton">First Button</button>
<button id="secondbutton" class="hidebutton">Second Button</button>
</body>
</html>

Open in new window

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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now