@@ -7,7 +7,13 @@ const sectionLeft = document.querySelector(".section-left");
7
7
* in definitions
8
8
*/
9
9
function renderHTML ( DOMElement , text , bulletPointText , image ) {
10
- DOMElement . innerHTML = `<div class='def-text'>${ text } </div><div class="bullet-text">${ bulletPointText } </div>${ image } ` ;
10
+ const HTMLText = `<p class='def-text'>${ text } </p>` ;
11
+ const HTMLBulletPoints = `<div class="bullet-text">${ bulletPointText } </div>` ;
12
+ const HTMLImage = image ? `<img class="image"src=${ image } >` : null ;
13
+
14
+ DOMElement . innerHTML = image
15
+ ? `${ HTMLText } ${ HTMLBulletPoints } ${ HTMLImage } `
16
+ : `${ HTMLText } ${ HTMLBulletPoints } ` ;
11
17
}
12
18
13
19
function renderBulletPointsAsList ( bulletPoints ) {
@@ -18,7 +24,7 @@ function renderBulletPointsAsList(bulletPoints) {
18
24
. join ( "" ) ;
19
25
}
20
26
21
- // when the user clicks on a link in the left panel update the DOM
27
+ // When the user clicks on a link in the left panel update the DOM
22
28
sectionLeft . addEventListener ( "click" , function ( e ) {
23
29
const sectionRight = document . querySelector ( ".section-right" ) ;
24
30
const selectedValue = e . target . id ;
@@ -28,8 +34,10 @@ sectionLeft.addEventListener("click", function (e) {
28
34
29
35
const { image : imageUrl , text, bulletPointItems } = selectedDefinition ;
30
36
31
- const HTMLImage = `<img class ="images"src=${ imageUrl } >` ;
32
- const HTMLBulletPoints = renderBulletPointsAsList ( bulletPointItems ) ;
33
-
34
- renderHTML ( sectionRight , text , HTMLBulletPoints , HTMLImage ) ;
37
+ renderHTML (
38
+ sectionRight ,
39
+ text ,
40
+ renderBulletPointsAsList ( bulletPointItems ) ,
41
+ imageUrl ?? null
42
+ ) ;
35
43
} ) ;
0 commit comments