Module: DOM::Attributes

Included in:
Element
Defined in:
opal/fron/dom/modules/attributes.rb

Overview

Attributes

Instance Method Summary collapse

Instance Method Details

#[](name) ⇒ String

Returns the value of the attribute with the given name

Parameters:

  • name (String)

    The name of the attribute

Returns:



9
10
11
# File 'opal/fron/dom/modules/attributes.rb', line 9

def [](name)
  `#{@el}.getAttribute(#{name}) || Opal.nil`
end

#[]=(name, value) ⇒ type

Sets the value of the attribute with the given name with the given value

Parameters:

Returns:

  • (type)
    description


19
20
21
22
23
24
25
# File 'opal/fron/dom/modules/attributes.rb', line 19

def []=(name, value)
  if value
    `#{@el}.setAttribute(#{name},#{value})`
  else
    remove_attribute name
  end
end

#attribute?(name) ⇒ Boolean

Returns if the element has the given attribute

Parameters:

  • name (String)

    The attribute

Returns:

  • (Boolean)

    True / False



32
33
34
# File 'opal/fron/dom/modules/attributes.rb', line 32

def attribute?(name)
  `#{@el}.hasAttribute(#{name})`
end

#remove_attribute(name) ⇒ Object

Removes the given attribute

Parameters:

  • name (String)

    The attributes name



39
40
41
# File 'opal/fron/dom/modules/attributes.rb', line 39

def remove_attribute(name)
  `#{@el}.removeAttribute(#{name})`
end