Checking element presence in RJS

I need to test whether an element exists before I do some RJS thing to
it. I currently have a small RJS snippet that looks like this:

page << “if $(‘foo’) {”
page[‘foo’].visual_effect :appear
page << “}”

This would make sense:

if page[‘foo’]
page[‘foo’].visual_effect :appear

But since that is executed as ruby the javascript “if” is not rendered.

Is there prettier, pure ruby, and better way to say this with RJS?

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