开发者

Jquery: Set each odd li height = even height if odd li height is smaller than odd hieight?

Here what I need: for example, there's 4 list item. 1 2 3 4

If the height of 2 smaller than the height of 1, the height of the 2 = 1 same goes with 4 and 3, 6 and 5

I have the first part working somehow:

$(document).ready(function() {
   $('div.jShadow div > ul > li:odd').each(function(){
       $(this).height($(this).prev().height());
    });
 });

<div class="jShadow">
<div id="Menu2Div">
    <开发者_C百科;ul>
        <li>1
            <ul>
                <li>1-1</li>
                <li>1-2</li>
                <li>1-3</li>
                <li>1-4</li>
            </ul>
        </li>
        <li>2
            <ul>
                <li>2-1</li>
                <li>2-2</li>
                <li>2-3</li>
            </ul>
        </li>
        <li>3
            <ul>
                <li>3-1</li>
                <li>3-2</li>
            </ul>
        </li>
        <li>4
            <ul>
                <li>4-1</li>
            </ul>
        </li>
    </ul>
</div>

but I failed to do height check...


Does this work?

$(document).ready(function() {
   $('div.jShadow div > ul > li:odd').each(function(){
       $(this).css('min-height', $(this).prev().height() + 'px');
    });
 });

See fiddle http://jsfiddle.net/YXWVe/1/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜