Skip to content

Commit

Permalink
add utility function
Browse files Browse the repository at this point in the history
  • Loading branch information
emma-r-slight committed Nov 7, 2020
1 parent d5453ec commit afacf1b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "tabs-project",
"version": "1.0.0",
"description": "create tabs with vanilla js",
"main": "index.html"
"main": "index.html",
"scripts": {
"start": "parcel index.html --open",
"test": "jest",
Expand Down
5 changes: 5 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { container } from './utils'
const newEl = document.createElement('h1')
const text = document.createTextNode('Hello World')
newEl.appendChild(text)
container.appendChild(newEl)
21 changes: 21 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const container = document.getElementById('container')
const elementContent = document.createElement('div')
elementContent.id = 'elementContent'
const flexContainer = document.createElement('div')
flexContainer.id = 'flexContainer'

const addContent = (parentElement, element, addName, addClass, text) => {
const elementNode = document.createElement(element)
const textNode = document.createTextNode(text)
if (addId !== null) {
elementNode.id = addId
}
if (addClass !== null) {
elementNode.className = addClass
}

elementNode.appendChild(textNode)
parentElement.appendChild(elementNode)
}

export { addContent, container, elementContent, flexContainer }

0 comments on commit afacf1b

Please sign in to comment.