[Greasemonkey] Custom div constructor

Aaron Boodman zboogs at gmail.com
Thu May 12 12:58:12 EDT 2005


I don't know if you'll be able to use the constructor syntax, but how
about this:

function createSpecialDiv() {
  var elm = document.createElement("DIV");
  elm.prototype = new SpecialDiv();
  return elm;
}

function SpecialDiv() {}
SpecialDiv.prototype = HTMLDIVElement (or whatever its called)


On 5/12/05, Julien Couvreur <julien.couvreur at gmail.com> wrote:
> Hi,
> 
> I'm trying to write a custom div constructor.
> I tried:
> var CustomDiv = function() {
>   this.innerHTML = "custom text";
> }
> CustomDiv.prototype = document.createElement("div");
> 
> But that actually only creates one actual div...
> Any ideas?
> 
> Right now my workaround is to use a wrapping approach instead, but
> it's not what I really want:
> var CustomDiv = function() {
>     this.wrappedDiv = document.createElement("div");
>     this.wrappedDiv.innerHTML = "custom text";
> }
> 
> I also tried the following, but "this = ..." is not allowed.
> var CustomDiv = function() {
>     this = document.createElement("div");
>     this.innerHTML = "custom text";
> }
> 
> Thanks,
> Julien
> _______________________________________________
> Greasemonkey mailing list
> Greasemonkey at mozdev.org
> http://mozdev.org/mailman/listinfo/greasemonkey
>


More information about the Greasemonkey mailing list