Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

Element#set

#117

Element#set doesn't work with some properties case it accesses them as properties not as attributes

Reported by MadRabbit · November 19th, 2009 @ 07:02 PM

State: resolved
Milestone: 1.5.0 Release
Assigned to: nobody

Activity

  1. MadRabbit
    MadRabbit
    • State changed from new to resolved

    Following the less-surprize principle I've made this method to set the actual attributes directly via the 'setAttribute' method.

    NOTE: now it won't set unsupported attributes, like say if you try to assign a 'name' to a DIV element or something like that. So in case if you need to assign some custom properties of yours, you'll have to assign them manually to the instance, not through the 'set' method or the constructor.

    The only exception is the TEXTAREA.value property, in order to support textareas simultaneously with any other input element, the 'set' method will assign its value as a property not as an attribute.

    November 22nd, 2009 @ 07:45 PM

  2. MadRabbit
    MadRabbit
    • State changed from resolved to open

    gotta support custom attributes as it was before

    November 24th, 2009 @ 12:00 PM

  3. MadRabbit
    MadRabbit
    • State changed from open to resolved

    Ticket revisited,

    Evidently the attributes that are not supported as properties does not exist on an element instance, so I used this fact for this case, like that

    for (var key in hash) {
      if (this[key] === undefined)
        this.setAttribute(key, ''+hash[key]);
      
      this[key] = hash[key];
    }
    

    This way it works both with normal and custom attributes, handles standard attributes that are not available as properties, and it also works faster than previous solution.

    November 24th, 2009 @ 12:04 PM

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.