开发者

How to count DIV element and insert break line

I would like to insert a break line after the second or third DIV element. Any ideas how to use Jquery ot do that? Thanks

<div class="column"> 
    <h3>Web Development</h3> 
    <ul> 
        <li><a href="http://www.javascriptkit.com">JavaScript Kit</a></li>
        <li><a href="http://www.dynamicdrive.com/">Dynamic Drive</a></li>
        <li><a href="http://www.cssdrive.com">CSS Drive</a></li>
        <li><a href="http://www.codingforums.com">Coding Forums</a></li> 
        <li><a href="http://www.javascriptkit.com/domref/">DOM Reference</a></li>
    </ul> 
</div>

<div class="column"> 
    <h3>News Related</h3>
    <ul> 
        <li><a href="http://www.cnn.com/">CNN</a></li> <li><a href="http://www.msnbc.com">MSNBC</a></li>
        <li><a href="http://www.google.com">Google</a></li> <li><a href="http://news.bbc.co.uk">BBC News</a></li>
    </ul> 
</div>

<div class="column"> 
    <h3>Technology</h3> 
    <ul> 
        <li><a href="http://www.news.com/">News.com</a></li> 
        <li><a href="http://www.slash开发者_如何学JAVAdot.com">SlashDot</a></li> 
        <li><a href="http://www.digg.com">Digg</a></li>
        <li><a href="http://www.techcrunch.com">Tech Crunch</a></li>
    </ul>
</div>​


You can use :eq and after like this:

$('div.column:eq(1)').after('<br />');

That would insert new line only after second div. If you want to insert a new line after every second div (with respect to previous used div), you need to use :nth-child instead like this:

$('div.column:nth-child(2n)').after('<br />');
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜