Could you show an example of doing this? Extending built-in things wasn't the intention. I merely wanted to make a method that would grab the width for each object this method is applied to. Therefore making it easy to say: element.grabWidth(); to get the width of this element. jQuery did it, and I'd like to know how to do this too.
One other question, how to I make this update every time a change happens in the browser? Reason: to prevent having to refresh the web page each time something changes.
The objects position is what changes. I'm centering the box to the screen top and left. I'm more or less learning how to do this with pure JavaScript as a leaning thing.
What I said is still correct - you can still use CSS for this. Horizontal centering is easy though vertical centering is a bit trickier*.
Why am I harping on about CSS? Not only it is the most correct way (IMO) but it's easier than trying to position and move the thing with Javascript.
* Unless the situation has changed in the last couple years I find it easiest to use tables, be they HTML or CSS. vertical-align:middle on a display:table-cell is the best general-purpose way to center that I know. Otherwise check with Google.
Manipulate? Once set you wouldn't have to change it... At most it would be the toggling of class names, but no framework means you have to care (more) about compatibility yourself. Off-hand,
// given obj is the thing you're changing and "foo" is the class
if (obj.classList) {
obj.classList.toggle("foo");
} else if (obj.className.indexOf("foo") >= 0) {
obj.className = obj.className.replace(/foo/, "");
} else {
obj.className += " foo";
}