Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 89df696

Browse files
committed
Replace innerHTML with innerText
1 parent da506b5 commit 89df696

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

Week1/MAKEME.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ It should include the following components:
151151
2. A left-hand column that displays basic information about the selected repository.
152152
3. A right-hand column that displays a list of contributors to the repository.
153153
154+
>In case you run out of time, you can also do the contributors list in week 2.
155+
154156
**Functional Requirements:**
155157
156158
1. The list of repositories in the `select` element should be sorted (case-insensitive) on repository name.

homework/src/App.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ class App {
2929
}
3030
}
3131

32+
/**
33+
* Removes all child elements from a container element
34+
* @param {*} container Container element to clear
35+
*/
36+
clearContainer(container) {
37+
while (container.firstChild) {
38+
container.removeChild(container.firstChild);
39+
}
40+
}
41+
3242
/**
3343
* Fetch contributor information for the selected repository and render the
3444
* repo and its contributors as HTML elements in the DOM.
@@ -40,8 +50,7 @@ class App {
4050
const contributors = await repo.fetchContributors();
4151

4252
const container = document.getElementById('container');
43-
// Erase previously generated inner HTML from the container div
44-
container.innerHTML = '';
53+
this.clearContainer(container);
4554

4655
const leftDiv = Util.createAndAppend('div', container);
4756
const rightDiv = Util.createAndAppend('div', container);

homework/src/Util.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ class Util {
77
parent.appendChild(elem);
88
Object.keys(options).forEach((key) => {
99
const value = options[key];
10-
if (key === 'html') {
11-
elem.innerHTML = value;
10+
if (key === 'text') {
11+
elem.innerText = value;
1212
} else {
1313
elem.setAttribute(key, value);
1414
}

homework/src/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
parent.appendChild(elem);
2222
Object.keys(options).forEach((key) => {
2323
const value = options[key];
24-
if (key === 'html') {
25-
elem.innerHTML = value;
24+
if (key === 'text') {
25+
elem.innerText = value;
2626
} else {
2727
elem.setAttribute(key, value);
2828
}
@@ -34,9 +34,9 @@
3434
fetchJSON(url, (err, data) => {
3535
const root = document.getElementById('root');
3636
if (err) {
37-
createAndAppend('div', root, { html: err.message, class: 'alert-error' });
37+
createAndAppend('div', root, { text: err.message, class: 'alert-error' });
3838
} else {
39-
createAndAppend('pre', root, { html: JSON.stringify(data, null, 2) });
39+
createAndAppend('pre', root, { text: JSON.stringify(data, null, 2) });
4040
}
4141
});
4242
}

0 commit comments

Comments
 (0)