0

I'm having a lot of difficulty writing JS code that's elegant and I feel like I'm doing this very wrong.

The goal here is to just embed HTML snippets into the Dom that's stored in a Firestore Database as {html: <img>...</img>}, and I currently do it this way:

  document.addEventListener('DOMContentLoaded', function() {
    try {
      firebase.firestore().collection("content").get().then(function(querySnapshot) {
        querySnapshot.forEach(function(doc) {
            document.getElementById('content').insertAdjacentHTML('beforeend', doc.data().html);
        });
      });
    } catch (e) {
      console.error(e);
    }
  });

Is this the best way of doing this in JS?

Mr. Demetrius Michael
  • 2,326
  • 5
  • 28
  • 40

0 Answers0