Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to use the CSS Selector for dynamically chaging the listing.

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 114
    Comment on it

    Here we will learn how we can use the css selector to change the representation of the the navigation listing or other listing.

    In the below example we have listed some of the air sports and water sports and we will change the representation of the listing using the css selector.

    For Example:

    <!--doctype html-->
    <html>
        <head>
            <title>Example addClass Jquery</title>
            <style type='text/css'>
    
            /*this styling will implemented on the html element with id='convayence'*/
    
            .horizontal-listing {
                float: left;
                list-style-type: circle;
                margin: 15px;
            }
    
            /*this styling will change the background color of the lising*/ 
    
            .sub-listing {
                background: #3683D6;
                color:red;
             }
    </style>
    </head>
    <div id='list1'>
        <p>Listing before adding the class .horizontal-listing and sub-listing</p>
    <ul id="convayence1">
    
    <li>Air sports
    <ul>
    <li>Aerobatics</li>
    <li>Gliding</li>
    <li>Ballooning</li>
    <li>Parachuting</li>
    <li>Paragliding</li>
    </ul>
    </li>
    
    <li>Water sports
    <ul>
    <li>Swimming</li>
    <li>Diving</li>
    <li>Water aerobics</li>
    <li>Water Polo</li>
    <li>Aquajogging</li>
    </ul>
    </li>
    </ul>
    </div>
    
    <div id='list2'>
        <p>Listing after adding the class .horizontal-listing and sub-listing</p>
    
    <ul id="convayence2">
    
    <li>Air sports
    <ul>
    <li>Aerobatics</li>
    <li>Gliding</li>
    <li>Ballooning</li>
    <li>Parachuting</li>
    <li>Paragliding</li>
    </ul>
    </li>
    
    <li>Water sports
    <ul>
    <li>Swimming</li>
    <li>Diving</li>
    <li>Water aerobics</li>
    <li>Water Polo</li>
    <li>Aquajogging</li>
    </ul>
    </li>
    </ul>
    </div>
    
    <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
    <script>
    $(document).ready(function() {
    
    $('#convayence2 > li').addClass('horizontal-listing'); //Adding the horizontal-listing class
    
    //Adding the sub-listing class on listing other on elements other than under horizontal-listing class
    
    $('#convayence2  li:not(.horizontal-listing)').addClass('sub-listing');
    
    });
    </script>
    </body>
    </html>
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: