In the last tutorial, you learned some basics of jQuery and its awesome features.
So let’s go ahead, In this tutorial, I will demonstrate the 12 Most Helpful jQuery Methods and Functions which are really useful to learn advanced jQuery.
Let’s begin:
12 Most Helpful jQuery Methods and Functions
1.Each Function():
Uses: The $.each()
Use as for loop, and $(this)
refer the current object of the loop
For Example:
//Show text value of each 'one' attribute one by one
$('li.one').each(function(){
alert($(this).text());
});
2.Map Function():
Uses: The $.map() method applies a function to each item in an array.
Example:
function sampleFunction(ele) {
return ele * 2;
}
var item = [1,2,3,4];
var newitem2 = $.map(item, sampleFunction);
console.log(newitem2); // [2,4,6,8]
3.append Function():
Uses: Append inserts content at the end of the selected elements.Example:
//inserts content at the end of the selected elements
$('p.one').append('Hello!this is append...');
4.prepend Function():
Uses: Prepend inserts content at the beginning of the selected elements.
Example:
//Prepend inserts content at the beginning of the selected elements.
$('p.two').prepend('Hello!this is prepend...');
Read, How to check-uncheck all checkboxes With jQuery
5.After Function():
Uses: After inserts content after the selected elements.
Example:
//inserts content after the selected elements.
$('p.two').after('Hello!this is prepend...');
6.Before Function():
Uses: Before inserts content before the selected elements.
Example:
//before inserts content before the selected elements.
$('p.one').before('Hello!this is append...');
7.Find Function():
Uses: Find Function is used to find any element from Html.
Example:
//Find 'h1' attribute inside 'one class'
$('.one').find('h1').css('background','blue');
8.Load function():
Uses: Load Function is used to load any external content from another file.
Example:
//it loads test.html file from external source
$('#content').load('test.html');
read more:https://tutscoder.com/post/jquery-most-usefull-functions-list