开发者

jquery detect nunber of item inside a div and add a class

I would like to add a style to a div if number of items within this div is >2

If number of <ie:menuitem> is more than 2 then set div with id of s4-ribbonrow to display:block;

<div class="s4-pr" id="s4-ribbonrow" style="height: 135px; display: none;">
<ie:menuitem menugroupid="100"></ie:menuitem>
<ie:menuitem menugroupid="100"></ie:menuitem>
<ie:menuitem menugroup开发者_Go百科id="100"></ie:menuitem>
<ie:menuitem menugroupid="100"></ie:menuitem>
</div>

How would i do that in Jquery?


Is this what you want to achieve?

var $row = $('#s4-ribbonrow');

if ($row.children().length > 2)
    $row.css('display', 'block'); 


You could try

var ribbon = $('#s4-ribbonrow'),
    menuitems = ribbon.children().filter(function(){
        return this.nodeName = 'IE:MENUITEM';
    });

if (menuitems.length>2){
    ribbon.show();
}

Demo at http://jsfiddle.net/gaby/mQaBQ/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜