public Method

GeneratorMethods.[](id)

Returns a element reference by finding it through id in the DOM. This element can then be used for further method calls. Examples:

page['blank_slate']                  # => $('blank_slate');
page['blank_slate'].show             # => $('blank_slate').show();
page['blank_slate'].show('first').up # => $('blank_slate').show('first').up();

You can also pass in a record, which will use ActionController::RecordIdentifier.dom_id to lookup the correct id:

page[@post]     # => $('post_45')
page[Post.new]  # => $('new_post')

Source Code

# File action_view/helpers/prototype_helper.rb, line 660
def [](id)
  case id
    when String, Symbol, NilClass
      JavaScriptElementProxy.new(self, id)
    else
      JavaScriptElementProxy.new(self, ActionController::RecordIdentifier.dom_id(id))
  end
end
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.