id selector in jQuery with example



id selector returns the element with the specified id.


Example :



    <html>
    <head>
    <title>ID Selector</title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"> 
    </script>
    <script type="text/javascript">
    $(document).ready(function()
    {
    $("#myButton").click(function()
    {
    $("#myDiv").css({'font-size':'20px','background-color':'Orange'});
    });
    });
    </script>
    </head>
    <body>
    <div id="myDiv">This is div.</div>
    <button id="myButton">Click Me</button>
    <button onclick="location.reload()">Reset</button>
    </body>
    </html>
    

Demo :





In the above example, we have used ID selector. Id selector select the elements with the specified id on the page. In above example, it selects the elements with specified id and applies CSS to it.

0 comments:

Post a Comment