Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions collections/DOM/class-manipulation-prototype.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
~~~ javascript
// el.addClass('the-class');
Element.prototype.addClass = function(newClass) { this.classList.add(newClass); return this; }

// el.removeClass('the-class');
Element.prototype.removeClass = function(oldClass) { this.classList.remove(oldClass); return this; }

// el.toggleClass('the-class');
Element.prototype.toggleClass = function(thisClass) { this.classList.toggle(thisClass); return this; }

// if(el.hasClass('the-class'))
Element.prototype.hasClass = function(thisClass) { return this.classList.contains(thisClass); }
~~~
5 changes: 5 additions & 0 deletions collections/DOM/get-set-element-value-prototype.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
~~~ javascript
// set value --> el.val('Hello World');
// get value --> el.val();
Element.prototype.val = function(newValue) { if(newValue === undefined) return this.value; this.value = newValue; return this; }
~~~
10 changes: 10 additions & 0 deletions collections/DOM/hide-show-an-element-prototype.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
~~~ javascript
// el.hide();
Element.prototype.hide = function() { this.style.display = 'none'; return this; }

// el.hide();
Element.prototype.show = function() { this.style.display = ''; return this; }

// el.toggle();
Element.prototype.toggle = function() { this.style.display = (this.style.display !== 'none') ? 'none' : ''; return this; }
~~~