Skip to content

Instantly share code, notes, and snippets.

@SackeyDavid
Created October 17, 2021 21:24
Show Gist options
  • Save SackeyDavid/cf66735d7807615565b6d87c89695137 to your computer and use it in GitHub Desktop.
Save SackeyDavid/cf66735d7807615565b6d87c89695137 to your computer and use it in GitHub Desktop.
Add elements dynamically to HTML DOM
// parent div
var checkboxDiv = document.querySelector('#must-haves');
if(checkboxDiv.childElementCount > 0) {
let checkboxDivContents = checkboxDiv.innerHTML;
let str = checkboxDivContents + '<table><tbody><tr><td><ion-checkbox class="checkbox" checked="true" style="width: 50vw;--border-radius: .35rem;--background: #EEF0F2;--border-color: #EEF0F2;" color="dark"></ion-checkbox></td><td style="position: relative;top: -.19rem;"><span style="margin-left: calc(-50vw + 2.15rem)">'+ instructionData.instruction + '</span></td></tr></tbody></table>';
checkboxDiv.innerHTML = str;
} else {
checkboxDiv.innerHTML = this.addCheckbox(instructionData.instruction);
}
addCheckbox(text: string) {
let str = '<table><tbody><tr><td><ion-checkbox class="checkbox" checked="true" style="width: 50vw;--border-radius: .35rem;--background: #EEF0F2;--border-color: #EEF0F2;" color="dark"></ion-checkbox></td><td style="position: relative;top: -.19rem;"><span style="margin-left: calc(-50vw + 2.15rem)">'+ text + '</span></td></tr></tbody></table>';
return str;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment