1.0.3 • Published 5 years ago

sho88-createelem v1.0.3

Weekly downloads
3
License
ISC
Repository
github
Last release
5 years ago

CreateElem(ent)


What is this?

A set of simple DOM manipulation functions, and that's it.


Install via NPM

npm i sho88-createelem


How to use

<!DOCTYPE html>
<html>
	...
	<body>
		<div id="app"></div>

		<script>
		(function () {
			const element = CreateElem.create('div', {
				class: 'app',
				events: {
					click: function () {
						// do what you need to do in here...
					}
				}
			});

			CreateElem.append(document.getElementById('app'), element);
		}());
		</script>
	</body>
</html>

References

CreateElem.create(tag, attributes, content) Function used to create an element, with the following arguments: 1. tag - element 2. attributes - An object literal that contains the attributes of this element. You can pass an object in, or just place null if you do not intend to add any attributes. In addition to attributes being added, you can add an events property that will hold event listeners for the element you are creating. 3. This will be a string representation of the text you would like to add inside this component.

CreateElem.append(container, child) Function used to append a DOM element (or an array of DOM elements) into another DOM element as shown above in the 'How to use' section. 1. container - DOM element. 2. child - DOM element (this can either be a DOM element, or an array containing DOM elements).

CreateElem.exists(element) Check to see if an element exists or not. This will return a boolean. 1. element - string representation of an element e.g .app

CreateElem.empty(element) Empties an element.

  1. element - This can either be a string representation of an element e.g .app or can be the DOM element itself.

Developed by


1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago