By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,848 Members | 3,202 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,848 IT Pros & Developers. It's quick & easy.

Constructors!!!

P: 55
Does anyone know if you can access/add to the prototype for an elements constructor with javascript? The idea is I would like to add default functionality to certain elements (specifically "Label" elements). The company that this project is for has all of their forms in flat html files that I load with ajax and add to object groups for easier manipulation, it would be really helpful if I could add the methods necessary when the html elements are loaded on the page.

Right now I just load all the elements currently loaded on the page into an object and iterate through them, applying methods depending on the tagName. It works fine, but after a few forms have been loaded the page obviously slows down. I know how to add to the constructor's prototype of other javascript objects, and I know the constructor for a label element is referenced with "HTMLLabelElement", but I can't seem to affect the prototype...any thought would be appreciated:)
Oct 24 '08 #1
Share this Question
Share on Google+
2 Replies


rnd me
Expert 100+
P: 427
a few examples:

Expand|Select|Wrap|Line Numbers
  1. HTMLTextAreaElement.prototype.toString=function(){return this.value}
  2. HTMLInputElement.prototype.toString=function(){return this.value}
  3. HTMLTableCellElement.prototype.toString=function(){return this.textContent}
  4. Element.prototype.__defineGetter__("innerText", function () {return this.textContent.toString()});
  5.  
remember that this won't work in IE7 and below...
Oct 24 '08 #2

P: 55
that's great, thanks! It just figures that this company would still be using ie6....internationally! Get on the ff bus people!
Oct 24 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.