There is a class

<div class="active"> текст </div 

How to extract text from it using js and write it to the url variable? I try this way, but it does not work. What am I doing wrong?

 <script type="text/javascript"> window.onload = function First () { var url = document.getElementsByClass('active'); var ds = url; aaa.href = ds; } </script> 
  • What is this line for var ds = url ? - Arnial
  • @Arnial debugged the previous function, do not pay attention - sbaikov

1 answer 1

Here's a sample code, the result is output in the browser console.

 window.onload = function First() { var url = document.getElementsByClassName('active'); for (var i = 0; i < url.length; i++) console.log(url[i].innerText); } 
 <div class="active">Test text</div>