javascript - JQuery get all elements by class name -


in process of learning javscript , jquery, went through pages of google can't seem working. i'm trying collect innerhtml of classes, jquery seems suggested plain javascript, document.write.

here's code far;

<div class="mbox">block one</div> <div class="mbox">block two</div> <div class="mbox">block three</div> <div class="mbox">block four</div>  <script> var mvar = $('.mbox').html(); document.write(mvar); </script> 

with this, first class shows under document.write. how can show block oneblock twoblock three? ultimate goal show them comma seperated block one, block two, block three, block four. thanks, bunch of relevant questions come none seem simple.

one possible way use .map() method:

var = $(".mbox").map(function() {     return this.innerhtml; }).get();  console.log(all.join()); 

demo: http://jsfiddle.net/y4bhh/

n.b. please don't use document.write. testing purposes console.log best way go.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -