jQuery Map Method Explained

Amit D
Updated on 09-Dec-2019 08:57:13

520 Views

The map method translates a set of elements in the jQuery object into another set of values in a jQuery array which may, or may not contain elements.The following are the parameters of jQuery.map() method:callback − The function to execute on each element in the set.ExampleYou can try to run the following code to learn how to work with jQuery.map() method:Live Demo           jQuery Map Method                              $(document).ready(function(){                         var ... Read More

Select a Subset of Matched Elements in jQuery

Amit D
Updated on 09-Dec-2019 08:55:37

322 Views

The slice( start, end ) method selects a subset of the matched elements. The following are the parameters of the slice() method:start − Where to start the subset. The first element is at zero. Can be negative to start from the end of the selection.end − Where to end the subset excluding end element. If unspecified, ends at the end of the selection.ExampleYou can try to run the following code to select a subset of the matched elements using the slice() method:Live Demo           jQuery slice() method                   ... Read More

Get Substring of a String in jQuery

Amit D
Updated on 09-Dec-2019 08:52:02

6K+ Views

To get substring of a string in jQuery, use the substring() method. It has the following two parameters:from: The from parameter specifies the index where to start the substring.to: The to parameter is optional. It specifies the index where to stop the extraction. This is an optional parameter, which extracts the remaining string, when nothing is mentioned.ExampleYou can try to run the following code to learn how to get substring of a string in jQuery:Live Demo           jQuery subtring                             ... Read More

jQuery andSelf Method Explained

Amit D
Updated on 09-Dec-2019 08:47:18

162 Views

The andSelf( ) method adds the previous selection to the current selection. The method is useful when you have multiple traversals in your script and then adding something that was matched before the last traversal.ExampleYou can try to run the following code to learn how to work with jQuery.andSelf() method:Live Demo           jQuery andSelf() method                          $(document).ready(function(){             $("div").find("p").andSelf().addClass("border");          });                          p, div {             margin:5px;             padding:5px;          }          .border {             border: 2px solid red;          }          .background {             background:yellow;          }                                  First Paragraph          Second Paragraph              

Get Objects by ID, Class, Tag and Attribute in jQuery

Amit D
Updated on 09-Dec-2019 08:04:36

968 Views

Here’s how you can get objects by ID Selector (#id), by Class Selector (.class), by Tag, and Attribute (.attr()).Get Object by Class SelectorExampleThe element class selector selects all the elements which match with the given class of the elements.Live Demo           jQuery Selector                          $(document).ready(function() {                 $(".big").css("background-color", "yellow");          });                                  This is first ... Read More

Fetch nth DIV from HTML Page using jQuery

Ricky Barnes
Updated on 09-Dec-2019 07:59:33

280 Views

To fetch the nth div from an HTML page, use the jQuery eq() method. It is used to access the index of an element in jQuery. The eq() method refers the position of the element.ExampleYou can try to run the following code to learn how to fetch nth div from an HTML page using jQuery. Here, we will fetch the 2nd div:Live Demo $(document).ready(function(){   $("#button1").click(function(){     alert($("div:eq(1)").text());   }); }); Paragraph One Paragraph Two - 2nd div selected Paragraph Three Which div?

Access Index of an Element in jQuery

Ricky Barnes
Updated on 09-Dec-2019 07:58:09

891 Views

To access the index of an element in jQuery, use the eq() method. The eq() method refers the position of the element.ExampleYou can try to run the following code to learn how to access index of an element in jQuery,Live Demo $(document).ready(function(){    $('ul li').eq(2).css({'background-color':'#E6B16A'});});   India   US   UK   Australia

Access Element with nth Index in jQuery

Ricky Barnes
Updated on 09-Dec-2019 07:50:04

1K+ Views

To access element with nth index from an HTML page, use the jQuery eq() method. It is used to access the index of an element in jQuery. The eq() method refers the position of the element.ExampleYou can try to run the following code to access element with nth index in jQuery. Here, element with 2nd index is considered:Live Demo $(document).ready(function(){    $('ul li').eq(2).css({'background-color':'#E6B16A'});});   India   US   UK   Australia

Difference Between Filter and Find in jQuery

Amit D
Updated on 09-Dec-2019 07:40:19

373 Views

jQuery filter() methodThe jQuery filter() method will return elements matching a specific criteria.ExampleYou can try to run the following code to learn how to work with jQuery.filter() method, Live Demo   $(document).ready(function(){     $("p").filter(".myclass").css("background-color", "gray");   }); Tutorialspoint Free Text Tutorials Free Video Tutorials Connecting Tutors jQuery find() methodThe jQuery.find() method will return the descendant elements of the selected element.ExampleYou can try to run the following code to learn how to work with jQuery.find() method, Live Demo  .myclass * {     display: block;   ... Read More

Locate Descendant Elements of a Specific Type

David Meador
Updated on 09-Dec-2019 07:17:53

146 Views

The find( selector ) method can be used to locate all the descendant elements of a particular type of elements. The selector can be written using any selector syntax.ExampleYou can try to run the following code to learn how to locate all the descendant elements of a particular type of elements:Live Demo           jQuery Example                              $(document).ready(function() {             $("p").find("span").addClass("selected");          });                              .selected {            color:blue;          }                         This is first paragraph and THIS IS BLUE       This is second paragraph and THIS IS ALSO BLUE        

Advertisements