|
9 | 9 | // Check if button already exists before creating it. |
10 | 10 | let buttonInstance = document.getElementById("button-total-cards-count"); |
11 | 11 | if (buttonInstance === null) { |
12 | | - // Create HTML for button. |
13 | | - let numberOfCardsButtonHTML = '<a id="button-total-cards-count" class="board-header-btn board-header-btn-invite ' + |
14 | | - 'board-header-btn-without-icon" title="Invite to board"><span class="board-header-btn-text">' + |
15 | | - 'Total cards: <b>' + numberOfCards + '</b></span></a>' |
| 12 | + // Build HTML button using native DOM manipulation methods. |
| 13 | + |
| 14 | + // Create parent hyperlink tag with relevant classes. |
| 15 | + let totalCardsCounterBtn = document.createElement("a"); |
| 16 | + totalCardsCounterBtn.setAttribute("id", "button-total-cards-count"); |
| 17 | + totalCardsCounterBtn.setAttribute("class", "board-header-btn board-header-btn-invite board-header-btn-without-icon"); |
| 18 | + |
| 19 | + // Create text span for total cards. |
| 20 | + let totalCardsSpan = document.createElement("span"); |
| 21 | + totalCardsSpan.textContent = "Total Cards: "; |
| 22 | + totalCardsSpan.setAttribute("class", "board-header-btn-text"); |
| 23 | + |
| 24 | + // Have total cards number be bold. |
| 25 | + let boldText = document.createElement("b"); |
| 26 | + boldText.textContent = String(numberOfCards); |
| 27 | + |
| 28 | + // Append children elements to parent element. |
| 29 | + totalCardsSpan.append(boldText); |
| 30 | + totalCardsCounterBtn.append(totalCardsSpan); |
| 31 | + |
16 | 32 | // Add button to Trello board. |
17 | | - document.getElementsByClassName("board-header-btns mod-left")[1].innerHTML += numberOfCardsButtonHTML; |
| 33 | + document.getElementsByClassName("board-header-btns mod-left")[1].append(totalCardsCounterBtn); |
18 | 34 | } else { |
19 | 35 | // Do nothing. |
20 | 36 | } |
|
0 commit comments