Use Javascript to Incrementally Add a Numer to a Selected Class I am dynamically generating content using Drupal. I am running javascript that places a div before another div. The code works fine, and looks like this:

  $(function() {
    $('.views-row-1 .content .body').insertBefore('.views-row-1 .content .field-name-field-image-one');

   });


My issue is that because the content is generated dynamically, the class "views-row-#" changes incrementally. For example, if I have 3 elements of content on the page, Drupal will create the class views-row-1 for the first one, views-row-2 for the second, views-row-3 for the third.

What I have done (which is not ideal) is written out a line of code for each piece of content like so:

  $(function() {
    $('.views-row-1 .content .body').insertBefore('.views-row-1 .content .field-name-field-image-one'); // check before() examples
    $('.views-row-2 .content .body').insertBefore('.views-row-2 .content .field-name-field-image-one'); // check before() examples
    $('.views-row-3 .content .body').insertBefore('.views-row-3 .content .field-name-field-image-one'); // check before() examples
    $('.views-row-4 .content .body').insertBefore('.views-row-4 .content .field-name-field-image-one') 
   });


I will never know how many pieces of content there will be because it's dynamic, so I'm looking to have the javascript add the number to the class. Is this even possible?
I don't think you really need to add the number to the class; the elements that you're targeting also have the .views-row class on them so you can use a bit of contextual jQuery to get the job done in a couple of lines:

$('.views-row').each(function(i,e) {
  $('.content .body', e).insertBefore($('.content .field-name-field-image-one', e));
});


I haven't tested that but I can't think of a reason why it wouldn't work.