HTML Editor
<!DOCTYPE html> <html lang="en-US"> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> </head> <body> <h1>jQuery toArray() Method</h1> <div>1</div> <div>2</div> <div>3</div> <p>Click on the button and check you console.</p> <button>Click Me</button> <script> $(document).ready(function(){ $("button").click(function(){ var x = $("div").toArray(); var arr= []; for(i=0; i < x.length; i++) arr.push(x[i].innerText); console.log(arr); }); }); </script> </body> </html>
OUTPUT
×

Save as Private