RJS Change Background Color

What’s the page.method to change the background color of a DOM element?
I’m
trying to change the background color of a couple of styled

  • 's when
    an
    Ajax link is clicked.

    Thanks,
    David

  • David,

    Use Element.addClassName(element, className) and CSS.

    Hope this helps,
    Zack

    Thanks for the answer, Zack.

    I’m not sure quite how to use that method, though. Fitting
    Element.addClassName into an RJS file won’t work, and
    page.add_class_name"id of element", “class name” throws an error
    saying AddClassName is not
    defined.

    • David

    page<<"$(‘theElement’).style.background=‘red’" also works for me.

    The $ javascript operator fetches the element with the name of its
    argument

    What’s the page.method to change the background color of a DOM element?
    I’m
    trying to change the background color of a couple of styled

  • 's when
    an
    Ajax link is clicked.

    Thanks,
    David

  • Try this:

    page.call ‘Element.addClassName’, ‘element_id’, ‘class_name’

    Zack

    page << “Element.addClassName(element, className)”

    David R. wrote:

    Thanks for the answer, Zack.

    I’m not sure quite how to use that method, though. Fitting
    Element.addClassName into an RJS file won’t work, and
    page.add_class_name"id of element", “class name” throws an error
    saying AddClassName is not
    defined.

    • David

    This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

    | Privacy Policy | Terms of Service | Remote Ruby Jobs