Selector #id : To access element with its id.


Here we will see how to access an element in jQuery with its id. Recall the code that we use in javascript to get an element with its id:
document.getElementById("firstptag")
Now the same can be achieved in jQuery using a few characters like the following: $("#fristptag")
So the points that are required to be noted are as follows: A "#" i.e. hash is used when we want to refer any element with its id.
Now let us look at one short example to clear this: <!--code starts from here--> <script type='text/javascript'> $("#firstptag").append("What are you doing today !! "); </script> <p id="firstptag">Hello how are you !! </p> <p> Howz life going on....!! </p> <!--code ends here-->
Now when you will execute the above code, you will get the following output: Hello how are you !! What are you doing today !! Howz life going on....!!

Leave a Reply

Your email address will not be published.