I want to get the data of each div.p into a json format like one below so i can send it over an ajax request. My loop function only returns the data of the first div three time. Why ?
It comes down to expectations. With a variable called value, people are likely to expect it to be a number value, or at worst some kind of string value.
In your code it’s not a number or a string though, it’s an element. As such letting it remain as value can lead to easy confusions and mistakes. We should call it something that helps people to understand what it is. Because frequently those other people are us too.
Calling it el is a very generic way to let people know that it’s an element. More specific is better though, so if .p means a paragraph or price, we could easily rename el to para or price instead depending on what’s more relevant.