Railstic

sharing experiences

How to check if a div exists in rjs?

| Comments


<body>
   <div id='main'>
      Main Div
   </div>
</body>

render :update do |page|
   page << "if ($('main')){"
   page.replace_html 'main', :inline => 'Here it is'
   page << "}"
end

This ruby code checks if there is a DOM object that its id = “main”. If there is then changes its content to “Here it is”, if there is not do nothing.

Comments