Guys help pliz understand this code. I don’t quite understand why creating the variable text = textNode.data and at the end writing this line of code again, only in a different order textNode.data = text. And why do you need to use the .data method?

function animate_string(id) { var element = document.getElementById(id); var textNode = element.childNodes[0]; // если представить что нет никаких потомков var text = textNode.data; setInterval(function () { text = text[text.length - 1] + text.substring(0, text.length - 1); textNode.data = text; }, 100); } 
  • And everything else you want you understand, especially about setInterval and modifying text ? - Alex Krass
  • Node no data properties and no descendants. Conclusion: Someone wrote a noob style. By meaning, it seems to be trying to flip a string, for some reason using a property and a delay. - user207618

1 answer 1

textNode.data = text - here we assign the new value to sv-vu data , which is obtained as a result of string concatenation (the last character becomes the first)
Sv-in data is responsible for the immediate value that is displayed in the textNode and changing it, we will change the text in textNode

 var text = textNode.data; // сохраняем текущий текст из textNode ... text = text[text.length - 1] + text.substring(0, text.length - 1); // изменяем текст ... textNode.data = text; // по сути меняем текст в элементе, на который ссылается textNode