Tags
Asked 2 years ago
10 Jun 2021
Views 358
Ed

Ed posted

get an array of text() in Jquery

get an array of text() in Jquery


$("body").text()

it give me all text from the body tag instead of i need array of text , not all text by one text
python

python
answered Jun 10 '21 00:00

you can use every element spereatly to grab the text array in Jquery


var text=[];
$("a").each(function(){          text[text.length]=$(this).text()   }) ;
$("h1").each(function(){          text[text.length]=$(this).text()   }) ;
$("h2").each(function(){          text[text.length]=$(this).text()   }) ;
$("span").each(function(){          text[text.length]=$(this).text()   }) ;
console.log(text)

we store all text in global text array and print it out after
Post Answer