Found 7800 Articles for Front End Technology

How does jQuery.filter() method work in jQuery?

Ricky Barnes
Updated on 13-Jun-2020 12:34:34
The jQuery filter() method will return elements matching a specific criteria. The following are the parameters for the jQuery.filter() methods,S.NoParameterDescription1criteriaThis specifies a selector expression, or one or more elements. These elements are returned from a group of selected elements.2function(index)This specifies a function to run for every element. This is an optional parameter.ExampleYou can try to run the following code to work with jQuery.filter(),Live Demo   $(document).ready(function(){     $("p").filter(".myclass").css("background-color", "gray");   }); Tutorialspoint Free Text Tutorials Free Video Tutorials Connecting Tutors

How to change first and last elements of a list using jQuery?

Ricky Barnes
Updated on 18-Dec-2019 07:35:28
To change the first and last elements of a list use the eq() method.ExampleYou can try to run the following code to change first and last elements of a list using jQuery:Live Demo    $(document).ready(function(){    $("#list li:eq(2)").after($("#list li:eq(0)"));  });     This year's ranking:   India   US   UK Last year's ranking:   India   US   UK

How to access element with nth index in jQuery?

Ricky Barnes
Updated on 09-Dec-2019 07:50:04
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

How to access index of an element in jQuery?

Ricky Barnes
Updated on 09-Dec-2019 07:58:09
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

How to fetch nth div from an HTML page using jQuery?

Ricky Barnes
Updated on 09-Dec-2019 07:59:33
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?

How to get objects by ID, Class, Tag, and Attribute in jQuery?

Amit D
Updated on 09-Dec-2019 08:04:36
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

How to escape square brackets in jQuery selector?

Amit D
Updated on 18-Dec-2019 07:33:37
To escape square brackets in jQuery selectors is quite easy. Let’s see with an example of escaping the brackets in the name of the box.ExampleWhatever you will select, will get added to the textarea on button click.Live Demo $(document).ready(function() {     $("#addnow").click(function () {        $("#myselect :selected").each(function () {           $("#text").val($("#text").val() + $(this).text() + "");        });     }); });     email@example.com     David Select and Click to Add

How to write a jQuery selector to find links with # in href attribute?

Amit D
Updated on 18-Dec-2019 07:34:31
ExampleYou can try to run the following code to write a jQuery selector to find links with # in href. Here,^ is used to find links starting with # in href.Live Demo $(document).ready(function(){    $('a[href^="#"]').click(function(){       alert('Success! Selected link starting with # in href.');    }); }); Demo C++

How to use JavaScript variables in jQuery selectors?

Amit D
Updated on 19-Dec-2019 06:24:39
It’s quite easy to use JavaScript variables in jQuery selectors.ExampleLet’s seen an example to use JavaScript variables in jQuery to hide an element:Live Demo $(document).ready(function(){    $("input").click(function(){         var name = this.name;       $("input[name=" + name + "]").hide();     } );     }); Heading 1 To hide the buttons, click on it.

How do we use jQuery selector eq:()?

David Meador
Updated on 18-Dec-2019 07:38:02
If you want to select an element with a specific index, then use the jQuery selector eq(). Here, set the index number to select the element.ExampleYou can try to run the following code to learn how to use jQuery selector eq():Live Demo $(document).ready(function(){    $("p:eq(1)").css("background-color","red"); }); Heading 1 This is demo text. This is another text. This is demo content
Advertisements