Grabbing text from elements and turning into array - then inserting that array back into the DOM

Grabbing text from elements and turning into array - then inserting that array back into the DOM

Hi all,

I would like to turn the text of a group of <h5> elements that are in a div with the id #parent into an array. This array would then appended to another div, with some html wrapped around each value. Can't actually find much documentation on this out there, wondering if any experienced forumites know how to do this. Here's the jQuery I've tried:

  1. var optiontriggers = $('#parent h5').serializeArray(), innerHTML;
  2.                     $.each(optiontriggers, function (i, field) {
  3.                         $('.optioninsert').append('<span class="optiontrigger">' + innerHTML + '</span>');
  4.                     });

It doesn't throw an error in the console, but it doesn't do anything else either. Any ideas? Perfectly happy to be told that I'm approaching this entirely the wrong way.

All help very much appreciated!

Thanks