In this post of JQuery, I will explain the three functions eq(), first(), and last() functions with a example. Below is the complete code for reference 1 <html> 2 <head> 3 <a href=”https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js”>https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js</a> 4 </head> 5 <body> 6 7 function selectElement() { 8 var $elements = $(‘a’); 9 10 var $indexedElement = $elements.eq(0); 11 alert($indexedElement.length);…… Continue reading eq(), first() and last() JQuery functions
Category: JQuery
Selecting elements by their attributes
In this post of JQuery, I will show how to select elements using their attributes. Below is the complete html code that will be used as an example 1 <html> 2 <head> 3 <a href=”https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js”>https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js</a> 4 </head> 5 <body> 6 7 function selectElement() { 8 var $element = $(‘a[href]’); 9 $(‘#input1’).val($element.length); 10 11 $element =…… Continue reading Selecting elements by their attributes
Selecting elements that are descendants of another element
In this post of JQuery, I will show how to select elements that are descendants of another element. Below is the complete html code that will be used as an example 1 <html> 2 <head> 3 https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js 4 </head> 5 <body> 6 7 function selectDescendantElement() { 8 var $element = $(‘div li’); 9 alert($element.length); 10…… Continue reading Selecting elements that are descendants of another element
Selecting elements that are direct children of another element
In this post of JQuery, I will show how to select elements that are direct childrens of another element. Below is the complete html code that will be used as an example 1 <html> 2 <head> 3 https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js 4 </head> 5 <body> 6 7 function selectElementByHierarchy1() { 8 var $element = $(‘#Items1 > li’); 9…… Continue reading Selecting elements that are direct children of another element
Selecting elements by their tag name
In this post of JQuery, I will explain how to select elements by their tag name. The syntax is as shown below $(‘tagName’) This will return one object or collection of more than one objects based on how many elements are there in the html matching the tagname. In the below example when the button…… Continue reading Selecting elements by their tag name
Selecting elements using Class selector
In this post of JQuery, I will show how to select elements using class selector. Class selector is used to retrieve elements whose class attribute’s value matches with the one specified in the selector. Class selector also selects elements whose class attribute’s value have multiple class name and one of them matches with the one…… Continue reading Selecting elements using Class selector
Selecting particular element using ID selector
In this post of JQuery, I will introduce you to id selector. The syntax of id selector is particular element’ attribute id value prepended by ‘#’ symbol, for eg #button. It is used to select one particular element whose id matches the id given in the $ method. Below is an example 1 <html> 2…… Continue reading Selecting particular element using ID selector
Universal Selector *
In this post of JQuery, I will introduce you to universal selector, represented by * symbol. It is used to select all the elements in the html page. Below is an example 1 <html> 2 <head> 3 https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js 4 </head> 5 <body> 6 7 function selectAll() { 8 var $all = $(‘*’); 9 alert($all); 10…… Continue reading Universal Selector *