title: How to refresh DOM after changing data attribute
body: <p>I'm coding little CMS for translations of static pages to many languages. It dynamically refreshes and loads translations etc, but I've got a few bugs which I cannot fix. One of them is when you try to preview page of id 1, but before you were editing page of id 2, it always redirects you to preview of page of id 2.</p>
  
  <p>That's my button in template:</p>
  
  <pre><code>&lt;div class="edit-template-container"&gt;
     //other code
     &lt;button id="a-preview" href="#" class="btn btn-block" target='_blank'&gt;
        Preview template
     &lt;/button&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>And it's function to load preview in new window:</p>
  
  <pre><code>$('#a-preview').on('click', function () {
      var pageId = $('#language-choice-select').data('page-id');
      console.log(pageId);
      window.open('/main/staticPages&amp;staticPageId=' + pageId, '_blank');
  });
  </code></pre>
  
  <p>Then I've read some articles about event-delegation and assumed it could be my problem so changed that code to:</p>
  
  <pre><code>$('.edit-template-container').on('click', '#a-preview', function () {
      var pageId = $('#language-choice-select').data('page-id');
      console.log(pageId);
      window.open('/main/staticPages&amp;staticPageId=' + pageId, '_blank');
  });
  </code></pre>
  
  <p>But it stills redirects to page of id 2 if it was edited before. In DevTools Elements I can see that data-page-id is changed, but console.log always prints for example id: "2" if it was edited before.</p>
  
  <p>Data 'page-id' attribute is changed when I choose page to edit in table, on function which looks like that:</p>
  
  <pre><code>$('table').on('click', '.edit-table-btn', function () {
      var pageId = $(this).data("page-id");
      //the rest of code
      $('#language-choice-select').attr('data-page-id', pageId);
  });
  </code></pre>
  
  <p>What should I do to change page-id data-attribute dynamically in DOM? What should I know about this, are there any fine articles?</p>