jQuery first() methodAs its name implies, the first() method returns the first element of the selected elements. If we need to get the last element, we can use the last() method. SyntaxThis method doesn't accept any argument. The selector in the above syntax is mandatory to be specified. Let's see some of the illustrations to understand how to use the first() method. Example1In this example, we are using the first() method to get the first paragraph element from the set of elements. We are using the p as the selector, so the method will return the first paragraph element. Test it NowOutput After the execution of the above code, the output will be - ![]() After clicking the given button, the output will be - ![]() Example2In this example, we are using the first() method to get the first span element from the set of elements. Test it NowOutput After the execution of the above code, the output will be - ![]() After clicking the given button, the output will be - ![]()
Next TopicjQuery last() method
|
JavaTpoint offers too many high quality services. Mail us on h[email protected], to get more information about given services.
JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected].
Duration: 1 week to 2 week