Using ASP.NET AJAX - DOM Element Methods
(Page 2 of 4 )
For DOM elements, ASP.NET AJAX provides special methods for common scenarios like applying CSS classes. These methods are defined in theSys.UI.DomElementclass. For common features like setting CSS classes or removing them, CSS class methods take some keyboarding weight off developers’ shoulders.
Sys.UI.DomElement.addCssClass(element, className)
Adds a CSS class (className) to an HTMLelement.
Sys.UI.DomElement.containsCssClass(element, className)
Checks whether the CSS class definition of anelementcontains a certain CSS class.
Sys.UI.DomElement.removeCssClass
Removes a CSS class (className) from an HTMLelement.
Sys.UI.DomElement.toggleCssClass(element, className)
Checks whether the CSS class definition of anelement contains a certain CSS class (className). If it does, it removes this CSS class, otherwise it appends the CSS class. Apart from CSS classes, ASP.NET AJAX provides helper methods for some of the most often accessed properties of general HTML elements: width, height, and position.
Sys.UI.DomElement.getBounds(element)
Returns an object with the propertiesx,y,height,width, containing the x coordinate, y coordinate, height, and width of the given element.
Sys.UI.DomElement.getLocation(element)
Returns an object with the propertiesxandy, containing the x and y coordinates of the given element.
Sys.UI.DomElement.setLocation(element, x, y)
Sets the x and y coordinates of the given element.
Another method defined withinSys.UI.DomElementisgetElementById()—but you already know the shortcut for that,$get().
Next: Extensions to Existing JavaScript Objects >>
More ASP.NET Articles
More By O'Reilly Media
|
This article is excerpted from chapter four of Programming ASP.NET AJAX, written by Christian Wenz (O'Reilly, 2007; ISBN: 0596514247). Check it out today at your favorite bookstore. Buy this book now.
|
|