Opened 3 years ago

Last modified 20 months ago

#18887 new enhancement

toggle function for dom-attr

Reported by: art_clifford Owned by:
Priority: undecided Milestone: 1.14
Component: Core Version: 1.10.4
Keywords: Cc:
Blocked By: Blocking:


A couple of the more used dojo capabilities I use are dom-class and dom-attr

In dom-class you kindly included a toggle function where we can either call toggle() or toggle(true|false).

However, dom-attr doesn't have an equivalent function and for doing things like toggling a disabled attribute, it would be useful to do: domAttr.toggle(target,'disabled',null) domAttr.toggle(target,'disabled',null,true) domAttr.toggle(target,'disabled',null,false)


  • target usual dom node options for target
  • attributeName
  • valueWhenTrue (if null, a valueless attribute would be added like <input disabled>...)
  • targetState (optional boolean)

Return would be resulting state (true/false)

I know the functionality may be accomplished through use of has, add, and remove on the existing class, it just seems like a toggle conspicuously absent.

The idea is to simplify code in a script where you know the attribute value you set on an element but may need to toggle it on/off so:

this.href="" start with domAttr.toggle(target,'href',this.href,true); domClass.toggle(target,'inactive-url',false)

then in a click handler: domClass.toggle(target,'inactive-url',domAttr.toggle(target,'href',this.href));

This would mean repatedly clicking the element triggering the click handler would make a a url active/inactive. I'm not sure it is a great example, but should illustrate possibilities.

I'm sure the function itself would be shorter than this ticket.

Change History (2)

comment:1 Changed 3 years ago by dylan

Milestone: tbd1.13

comment:2 Changed 20 months ago by dylan

Milestone: 1.131.14
Note: See TracTickets for help on using tickets.