Selector .class : To access elements belonging to a class


jQuery provides a very easy syntax for accessing the objects that belongs to a particular class.
For example:- suppose we want to access all elements with class name "blackcolor". So we will write a small code as follows: $(".classname") or, $(".blackcolor")
To understand this feature of jQuery, let us take an example as follows: Creating 3 elements in html: <p> Hello </p> <p class='blackcolor'> How are you </p> <p class='blackcolor'> What are you doing ?</p>
Now we add some jQuery code.... <script type='text/javascript'> $(".blackcolor").before("####"); </script>
Now when we run this code, we will see the output as follows:
Hello
#### How are you #### What are you doing ?
It means that "####" is inserted before the tags whose class is "blackcolor".

Leave a Reply

avatar
  Subscribe  
Notify of