javascript - Creating JQuery div class filter not working -
i trying make filter jquery hides div's , shows div's depending on class inside called "brand", managing hide div's not show ones matching class.
the alert have added inside statement showing think may parent show, has got ideas?
the html:
<div class="section-link" id="section-tooltip" data-content="popup option trigger" rel="popover" data-placement="right" title="" data-original-title=""> <div class="section-features" style="display: none;"> <p><i class="icon-star"></i> protective, waterproof lid</p> <p><i class="icon-star"></i> enhanced wooden coating</p> <p><i class="icon-star"></i> long lasting materials</p> <p><i class="icon-star"></i> 2 year warranty</p> <p><i class="icon-star"></i> includes durable bag</p> </div> <div class="brand tp" style="display: none;"></div> <div class="price" style="display: none;"> £47.99</div> <a href="garden-games-picnic-table-sandpit-6407.html"> <img src="picnic_table_sandpit.jpg" title="garden games picnic table sandpit" alt="garden games picnic table sandpit" width="220"> <h3 align="center">garden games picnic table sandpit</h3> <p align="center"> <span> was: £69.99</span> <span> now: £47.99</span> <span class="button">more info</span> </p> </a> <a name="a6407"></a> </div>
/\ there 20 div's different brand classes example class="brand garden"
the js:
function brand(string){ var brand = string; $('.section-link').hide(); if ($('.section-link').children('.brand').hasclass(brand)) { alert(brand); $(this).parent().show(); } }
i testing via chrome url bar javascript: brand("tp");
any appreciated, simon
you need use multiple selector here because need fetch .brand
elements have specified class
function brand(string){ var brand = string; $('.section-link').hide(); $('.section-link').children('.brand.' + brand).parent().show(); }
demo: fiddle
Comments
Post a Comment