0
Personal I am starting in javascript and I have many questions related to objects. One of them is the following: Let’s assume that I create an object.
Here I have a list and I want to keep it inside an object and a function of this object serves to change the color of this list.
(That’s not exactly what I want to do but you can understand)
var Objeto = {
//Aqui eu guardarei meu elemento.
lista : document.getElementsByTagName('li'),
//E esta funcao server para alterar o style das LIs.
alt_cor : function(){
Objeto.lista.setAttribute("style", "color:red");
}
}
Objeto.alt_cor();
<ul class="lista_frutas">
<li>Banana</li>
<li>Laranja</li>
<li>Maça</li>
</ul>
Nice answer, but let me add something. And if I remove the for and outside the object add a setInterval() to execute this function every 1 second, and so the colors of the Lis automatically change in a certain range; as would the script?
– Wendel Gomes
@Wendelgomes Do you want to call alt_cor by changing one? or change all of them every time setInterval runs? Explain what doubt you have so you can explain better.
– Sergio
That change one by one.
– Wendel Gomes
This with the same object structure only that instead of using the for all will be changed quickly, use setInterval() to change them one by one.
– Wendel Gomes
@Wendelgomes => https://jsfiddle.net/md9txce5/ (I wrote a few more lines to make it interesting :) )
– Sergio
kkkkk Cool the scheme you created. I had done here only that the shape you made got much better. I used a function outside the object to perform the function that was inside I could not perform from inside the object. Thank you very much helped me a lot!
– Wendel Gomes