SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    May 2008
    Location
    Bhubaneswar, India
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post [Code Review] Using jQuery to select

    To select the sibling 'ol' elements, after the first 'ol' element; which doesn't contain a 'li' element that itself contains an 'ul' element

    The HTML source

    Code HTML5:
    <ol id="orderedlist">
            <li>First element</li>
            <li>Second element</li>
            <li>Third element</li>
        </ol>
     
        <ol id="orderedlist2">
            <li>First element, second list</li>
            <li>Second element, second list</li>
            <li>Third element, second list</li>
            <li>Li with child ul
                <ul>
                    <li>Child One</li>
                    <li>child two</li>
                </ul>
            </li>
        </ol>
     
        <ol id="orderedlist2">
            <li>First element, third list</li>
            <li>Second element, third list</li>
            <li>Third element, third list</li>
            <li>Li with child ul
                <ul>
                    <li>Child One</li>
                    <li>child two</li>
                </ul>
            </li>
        </ol>

    jQuery to select & add css
    Code JavaScript:
    /* Selects the sibling 'ol' elements after the :first 'ol' element which doesn't contain a 'li' element that itself contains an 'ul' element */
        $('ol:first~ol > li').not(':has(ul)').css({
            'border': '1px solid black',
            'background-color': 'pink'
        });

    Please review the above code & advice some improvements using jQuery

    P.S.: I'm a n00b to jQuery. So please explain your code.

    Thanx.

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,707
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by crownabhisek View Post
    Please review the above code & advice some improvements using jQuery
    No improvements come to mind. It seems to do the job well.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •