I am trying to call a function onload of elements so that I can specify different changes of each elements I am calling the function.
like i have many divs and each and every div has same data-attribure, I am calling all divs with same data-attribute. Each and every div has different html text, I want to call them, when I am loading the page and get those different values. Like in jQuery we call 'each' function. Here I am submitting my html and javascript code... that will draw a clear picture of it.
<-- html -->
<div data-attribute="one">
<span class='value'>1000</span>
</div>
<div data-attribute="two">
<span class='value'>420</span>
</div>
<div data-attribute="three">
<span class='value'>2000</span>
</div>
<!---- javascript ---->
var abc = document.querySelectorAll('[data-attribute]');
for (i= 0; i < abc.length; i++) {
abc[i].onload = function(){
// --------- working well with click / mousemove events -----
console.log('function called!');
};
}
I don't want to use any library or don't want to call the function on element.
P.S. also let me know if there is other option to do the same. Thank you..
onloador aloadevent listener depending on what sort of elements you're loading. I'm finding it hard to understand your question so this is the best I can offer at this moment in time.onloadhandler? It may be that you can perform an action when the whole page has loaded, and vary the behaviour depending on some other attribute of the elements.