Tags
Asked 3 years ago
10 Jun 2021
Views 293
Scarlett

Scarlett posted

Get the text from all elements with the same class


<div class="menu">Home</div>
<div class="menu">Categories</div>
<div class="menu">Contact us</div>
<div class="menu">About us</div>


how to get the text from all elements with the same class
shabi

shabi
answered Jun 10 '21 00:00

following code will get all text with given class


function getText(classname){
 var text =[];
$("."+classname).each(function(){
text[text.length]=$(this).text();
});
return text;
}
getText("menu");

will return all texts in array
Post Answer