Method: Browser::DOM::Element#style

Defined in:
opal/browser/dom/element.rb

#styleCSS::Declaration #style(data) ⇒ self #style(&block) ⇒ self

Overloads:

  • #styleCSS::Declaration

    Return the style for the element.

    Returns:

  • #style(data) ⇒ self

    Set the CSS style as string or set of values.

    Parameters:

    Returns:

    • (self)
  • #style(&block) ⇒ self

    Set the CSS style from a CSS builder DSL.

    Returns:

    • (self)


368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
# File 'opal/browser/dom/element.rb', line 368

def style(data = nil, &block)
  style = CSS::Declaration.new(`#@native.style`)

  return style unless data || block

  if String === data
    style.replace(data)
  elsif Hash === data
    style.assign(data)
  elsif block
    style.apply(&block)
  else
    raise ArgumentError, 'unknown data type'
  end

  self
end