How to toggle elements with jQuery? -


i building website page has 16 items of apparel.

i want simple text navigation has option show , hide products either men, women, , all.

navigation

<ul class="sortnav"> <li class="first">view:</li> <li class="men button">men</li> <li class="women button">women</li> <li class="all button active">all</li> </ul> 

products code

<span class="prod men">guys shirt</span> <span class="prod men">guys pant </span> <span class="prod women">girls pant</span> <span class="prod women">girls pant</span> 

tricky part
1 button can "active". , class visible (one or two) triggered.

thanks in advance.

thanks! kinda combined 2 responses. check out...

$('.products li.prod').toggle(true);  $('.sortnav li.button').click(function () {     $('.sortnav li.button').removeclass('active');     $(this).addclass('active'); });  $('.sortnav li.men').click(function () {     $('.products li.prod').toggle(false);     $('.products li.men').toggle(true); });  $('.sortnav li.women').click(function () {     $('.products li.prod').toggle(false);     $('.products li.women').toggle(true); });  $('.sortnav li.all').click(function () {     $('.products li.prod').toggle(true); 

i compacted little bit code, should change li items

html:

<ul class="sortnav"> <li class="first">view:</li> <li section="mens" class="men button">men</li> <li section="womens" class="women button">women</li> <li section="all" class="all button active">all</li> </ul>  <div id="all" class="section">all clothing</div> <div id="mens" class="section">mens clothing</div> <div id="womens" class="section">womens clothing</div> 

js:

$(document).ready(function(){     $('li.button').click(function(){ //listens each element li class button         $('li.button').removeclass('active'); //removes 'active' class of them         $(this).addclass('active'); //adds class 1          $('.section').toggle(false);         $('#'+$(this).attr('section')).toggle(true);     });      $(".section").toggle(false); });   

as see added section attribute, can assign toggle(true) id. it's bit risky, works.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -