How to put the content of all elements with a certain class in a variable with Jquery -



How to put the content of all elements with a certain class in a variable with Jquery -

working jquery, want set content of elements specific class variable. here's example:

<div class="foo"> <div class="bar"><p>first set of text</p></div> <div class="bar"><p>second set of text</p></div> <div class="bar"><p>third set of text</p></div> <div class="bar"><p>n set of text</p></div> </div>

i set content of div elements class "bar" variable named "full". have tried next code grabs first div.

var total = $( ".bar" ).html();

i want content of string variable be

"<p>first set of text</p><p>second set of text</p><p>third set of text</p><p>n set of text</p>"

if have tried looking on net couldn't find answer. thinking using .each method few tries didn't work out well. idea?

thanks!

you right want utilize .each():

var total = ''; $('.bar').each(function () { total += $.trim($(this).html()); }) console.log(full);

jsfiddle example

jquery

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -