From e271d016062b0628024a7b3fd1a494e8240c9673 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Tue, 19 May 2020 08:33:12 +0300 Subject: [PATCH] Streamline application.js exampleModal code (#30819) * use `textContent` since we only need to add text * move comments --- site/assets/js/application.js | 8 +++++--- site/content/docs/5.0/components/modal.md | 7 +++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/site/assets/js/application.js b/site/assets/js/application.js index 9d0c684b72..51dc20d42d 100644 --- a/site/assets/js/application.js +++ b/site/assets/js/application.js @@ -66,14 +66,16 @@ var exampleModal = document.getElementById('exampleModal') if (exampleModal) { exampleModal.addEventListener('show.bs.modal', function (event) { - var button = event.relatedTarget // Button that triggered the modal - var recipient = button.getAttribute('data-whatever') // Extract info from data-* attributes + // Button that triggered the modal + var button = event.relatedTarget + // Extract info from data-* attributes + var recipient = button.getAttribute('data-whatever') // Update the modal's content. var modalTitle = exampleModal.querySelector('.modal-title') var modalBodyInput = exampleModal.querySelector('.modal-body input') - modalTitle.innerHTML = 'New message to ' + recipient + modalTitle.textContent = 'New message to ' + recipient modalBodyInput.value = recipient }) } diff --git a/site/content/docs/5.0/components/modal.md b/site/content/docs/5.0/components/modal.md index ece511ca2f..e42c104c51 100644 --- a/site/content/docs/5.0/components/modal.md +++ b/site/content/docs/5.0/components/modal.md @@ -547,8 +547,11 @@ exampleModal.addEventListener('show.bs.modal', function (event) { // and then do the updating in a callback. // // Update the modal's content. - exampleModal.querySelector('.modal-title').textContent = 'New message to ' + recipient - exampleModal.querySelector('.modal-body input').value = recipient + var modalTitle = exampleModal.querySelector('.modal-title') + var modalBodyInput = exampleModal.querySelector('.modal-body input') + + modalTitle.textContent = 'New message to ' + recipient + modalBodyInput.value = recipient }) {{< /highlight >}}