{"id":22562069,"url":"https://github.com/sanderhelleso/javascript-functions","last_synced_at":"2025-03-28T12:42:12.362Z","repository":{"id":96641459,"uuid":"136534002","full_name":"sanderhelleso/javaScript-Functions","owner":"sanderhelleso","description":"A list of my own handy javaScript functions","archived":false,"fork":false,"pushed_at":"2018-06-08T22:13:39.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-02T13:15:57.496Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sanderhelleso.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-06-07T21:40:47.000Z","updated_at":"2018-06-08T22:13:40.000Z","dependencies_parsed_at":null,"dependency_job_id":"46b57778-2073-4ce8-a533-20538052f94c","html_url":"https://github.com/sanderhelleso/javaScript-Functions","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sanderhelleso%2FjavaScript-Functions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sanderhelleso%2FjavaScript-Functions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sanderhelleso%2FjavaScript-Functions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sanderhelleso%2FjavaScript-Functions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sanderhelleso","download_url":"https://codeload.github.com/sanderhelleso/javaScript-Functions/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246034232,"owners_count":20712851,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-07T22:11:28.040Z","updated_at":"2025-03-28T12:42:12.344Z","avatar_url":"https://github.com/sanderhelleso.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# javaScript Fuctions\n\n\u003ch2\u003eA resusable function for createing specific elements and assign needed functionality to it like id, classes or events\u003c/h2\u003e\n\u003cp\u003eReally handy when creating elements is a common part of the application, cleans up the main code and gives you more flexibility when it comes to DOM manipulation\u003c/p\u003e\n\n```javascript\n// basic example on how to use the function\nconst htmlElement = createElement(\"h1\", \"mainHeading\", \"class1 class2 class3\", \"I love JS\", \"click\", \"myFunction\");\ndocument.querySelector(\"#heading\").appendChild(htmlElement);\nhtmlElement.click();\n\nfunction createElement(type, id, classes, text, eventType, eventFunction, parent) {\n\t// create an element with the given type\n\tconst ele = document.createElement(type);\n\n\t// assign the element an ID if an ID is present\n\tif (id != undefined) {\n\t\tele.id = id;\n\t}\n\n\t// assign the element class/classes if a class is present\n\tif (classes != undefined) {\n\t\tele.className = classes;\n\t}\n\n\t// assign the element an innerHTML if a text is present\n\tif (text != undefined) {\n\t\tele.innerHTML = text;\n\t}\n\n\t// assign the element an event listener if a event type and event is present\n\tif (eventType != undefined \u0026\u0026 event != undefined) {\n\t\tele.addEventListener(eventType, eval(eventFunction));\n\t}\n\n\t// append the element to a given parent if present\n\tif (parent != undefined) {\n\t\tparent.appendChild(ele);\n\t}\n\n\t// else return the created element\n\telse {\n\t\treturn ele;\n\t}\n}\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsanderhelleso%2Fjavascript-functions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsanderhelleso%2Fjavascript-functions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsanderhelleso%2Fjavascript-functions/lists"}