Toolkit:element prototypes
From Surebert wiki
Element prototypes
There are many Element prototypes, consult the auto-generated docs http://surebert.com/toolkit/docs to see them all
In core sb.js library
Element.prototype.addClassName
Adds a className to the Element, using this methods Element instances can have multiple classNames
javascript code
myElement.addClassName('redStripe');
Element.prototype.append
Appends another DOM element to the element as a child
javascript code
myElement.append(myOtherElement);
Element.prototype.appendAfter
Appends the element after another DOM element as a sibling e.g. append myElement to the parent of "#myDiv" as a sibling of "#myDiv" directly after "#myDiv"
javascript code
myElement.appendAfter('#myDiv');
Element.prototype.appendBefore
Appends the element before another DOM element as a sibling
e.g. append myElement to the parent of "#myDiv" as a sibling of "#myDiv" directly before "#myDiv"
javascript code
myElement.appendBefore('#myDiv');
Element.prototype.appendTo
Appends the element to another DOM element as a child
javascript code
//appends myElement to the page body myElement.appendTo('body'); //appends myElement to a div with the ID "myDiv" myElement.appendTo('#myDiv');
Element.prototype.appendToTop
Appends the element to the top DOM element as a child
javascript code
//appends myElement to the page body myElement.appendToTop('body'); //appends myElement to a div with the ID "myDiv" myElement.appendToTop('#myDiv');
Element.prototype.event
Used to set event cross-browser event handlers. For more information see sb.events. e.g. sets the backgroundColor property to red on click
javascript code
myElement.event('click', function(e){ //alerts the x value of the click alert(e.clientX); //alerts the innerHTML of myElement alert(this.innerHTML); });
Element.prototype.events
Used to assign multiple events at once
javascript code
var myDiv = $('#myDiv'); myDiv.events({ click : function(){ do something }, mouseover : function(){ //do somthing } });
Element.prototype.eventsAdded
Used keep track of events added to a Element. All events added with this.event are pushed into this array where they are stored for removal
javascript code
alert($('#myDiv').eventsAdded);
Element.prototype.getStyle
Calculates the absolute x position of an element
javascript code
myElement.getStyle('background-color'); //or myElement.getStyle('backgroundColor').
Element.prototype.getX
Calculates the absolute x position of an element
javascript code
myElement.getX();
Element.prototype.getY
Calculates the absolute x position of an element
javascript code
myElement.getY();
Element.prototype.hasClassName
Checks to see if the element has the className specified. Elements can have more than one className. returns boolean
javascript code
myElement.hasClassName('redStripe');
Element.prototype.lastEventAdded
Used keep track of the last event added to a Element.
javascript code
Element.prototype.remove
Removes an element from the DOM
javascript code
myElement.remove();
Element.prototype.removeClassName
Removes a className from the elements className array. Elements can have more than one className
javascript code
myElement.removeClassName('redStripe');
Element.prototype.replace
Replaces an element with another element in the DOM
javascript code
myElement.replace('#myOtherElement');
Element.prototype.setStyle
Both cssFloat and opacity are translated by surebert automatically for IE.
Sets a style property of an Element myElement.setStyle('backgroundColor', blue); //or myElement.setStyle('opacity', 0.5);
Element.prototype.styles
Sets multiple style properties for an Element Both cssFloat and opacity are translated by surebert automatically for IE.
javascript code
myElement.styles({ backgroundColor : '#000000', fontSize : '18px', border : '1px solid #FF0000', cssFloat : 'right' });
Extended Prototypes
These prototypes must be loaded via sb.include to by adding a script tag loading them in, e.g.
javascript code
sb.include('element.prototype.toggle')
or
html4strict code
<script type="text/javascript" src="/surebert/element/prototype/toggle.js"></script>