0

I need to append photos to my gallery. I want to make it by jQuery. I need to append to my gallery wrapper a structure of html tags like this:

                <article>
                  <div class="masonry-wall-brick-wrapper">
                    <figure>
                      <a>
                        <img />
                      </a>
                      <figcaption>Photo name</figcaption>
                    </figure>
                  </div>
                </article>

Now i am using this code to append:

masonryWallWrapper.append('lalala');

but it is looks like bad idea. I have very big and unreadable string. Is there any better or best way?

BJladu4
  • 263
  • 4
  • 15

1 Answers1

1

Instead of using an HTML string, I would clone() a template from the DOM and re-use it:

<article class="template">
  <div class="masonry-wall-brick-wrapper">
    <figure>
      <a>
        <img />
      </a>
      <figcaption class="photoname">Photo name</figcaption>
    </figure>
  </div>
</article>
$(function(){
    var $article = $('article.template').clone().removeClass('template');
    $article.find('.photoname').text('something');
    masonryWallWrapper.append($article);
});

You might find this easier. Just my two cents.

Johan
  • 35,120
  • 54
  • 178
  • 293