开发者

Check if class has element from an array? and hide the ones not pressed

Hi i'm trying to get something right.

First, I开发者_开发问答've got 12 menu items with an id. When the page is loaded i like to check if one or more of those id values are present in certain class.

Than i like to hide all the menu names (visually) witch are not pressed in the class.

The code so far: It doenst run the loop properly... or i dont make the array the right way

var test = $('.prov-nav').text().toLowerCase();
var cols = $.makeArray(test);
//alert(cols);

for ( var i = 0; i < cols.length; i++ )
{
if ( $('div[class^="cn-list-row"]').hasClass( cols[i] ) )
{
 // .hide menu names (visually) witch are not pressed in the class
break;  
}
else
{
alert('o no');
}

The html menu: Of witch the non pressed name in the class('div[class^="cn-list-row"]') should be visually hidden. .hide from the menu. (not only the id but the menu link itself)

<ul class="prov-nav">
<li><a href="#">Drenthe</a></li> 
<li><a href="#">Flevoland</a></li> 
<li><a href="#">Friesland</a></li> 
<li><a href="#">Gelderland</a></li> 
<li><a href="#">Limburg</a></li> 
<li><a href="#">Noord-Brabant</a></li> 
<li><a href="#">Noord-Holland</a></li> 
<li><a href="#">Overijssel</a></li> 
<li><a href="#">Utrecht</a></li> 
<li><a href="#">Zeeland</a></li> 
<li><a href="#">Zuid-Holland</a></li><br/>
<ul><!-- end of prov-nav -->

The DIV class is (dynamically) loaded from a wp plugin caled connections. In the end i replace the hide with an animation to make them fade to low opacity. So you see clearly the option you selected earlier.

The class could contain different category's. The strange names are state names but then from Holland.

<div class="cn-list-row-alternate vcard cag_custom_st drenthe particulier sporttherapie"></div>


Using IDs is a very bad idea.

<ul>
    <li class="nav-li">Drenthe</li>
    <li class="nav-li">Flevoland</li>
    <li class="nav-li">Friesland</li>
    <li class="nav-li">Gelderland</li>
</ul>

$('.nav-li').click(function (){
   $(this).show().siblings().hide();
});

classes are a way of grouping similar objects together so you don't have to use the IDs for each item :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜