-
Loop Syntax in jQuery
jQuery 3.0 is the most newest version of jQuery. There are many changes in it, but one of the important change
is the syntax of loop using for..of loop.For example earlier we use the syntax shown below:-
var $divelements = $("div");
for (var x=0; x< $divelements.length; x++){
$divelements[x].addClass("dummy");
}Here's the new syntax:-
var $divelements = $("div");
var i = 0;
for(var elm of $divelements) {
elm.addClass("dummy");
}With the help of this new syntax, you will get DOM elements, instead of jQuery collection. You not need to use index to get element, it will be directly accessible to you.
- This discussion was modified 8 years ago by Sourabh.
- This discussion was modified 7 years, 11 months ago by Forcetalks.
Log In to reply.
Popular Salesforce Blogs
What is Salesforce? Learn About Salesforce Products Here
Routine Automation collected all you need to know and combined it into an introduction to Salesforce. What does Salesforce do exactly? How to use Salesforce? In…
Salesforce Data Loss: Is Your Data Correct? How Can UI Contribute?
For a number of years security and safety of data has been the major reason which proved itself to be a hiccup in the path…
Popular Salesforce Videos
Which Objects are in the Salesforce Sales Cloud and Service Cloud?
In this video, We run through some of these diagrams. We'll also discuss some of the particular objects that you'll need to become familiar with as you…
Ask Me Anything with Salesforce Developers | Lightning Web Components
Join experts Mohith Shrivastava and Greg Whitworth for our monthly feature Ask Me Anything! This 1-hour session on Lightning Web Components is your chance to…
When to Code, Configuration, Code + Configuration in Salesforce
When to Code, Configuration, Code + Configuration in Salesforce by Nikunj Doshi, Salesforce Certified Technical Architect In this session: - Key Criteria in deciding the…