# Checking for elements before replace\_html on it

**URL:** <https://www.ruby-forum.com/t/checking-for-elements-before-replace-html-on-it/114461>\
**Category:** Rails\
**Created:** [September 12, 2007, 10:39pm UTC](https://www.ruby-forum.com/t/checking-for-elements-before-replace-html-on-it/114461 "2007-09-12T22:39:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [September 12, 2007, 10:39pm UTC](https://www.ruby-forum.com/t/checking-for-elements-before-replace-html-on-it/114461/1 "2007-09-12T22:39:24Z")

</div>

I do a whole lot of this from my controllers:

render :update do |page|  
page.replace\_html ‘someUniqueID’, “Some content”  
end

For one reason or another, sometimes this code is delayed and by the  
time it executes “someUniqueID” is no longer on the page. I need to  
work an if statement in somewhere to verify that ‘someUniqueID’ is  
still present on the page before the replace\_html gets fired off.

I’ve tried:

if page[‘someUniqueID’]  
Always returns true, even if someUniqueID is present

page.select(’#someUniqueID’).first.replace\_html ‘someContent’  
With this, somehow “replace\_html” gets converted to “replaceHTML” and  
then spits off:  
“replaceHtml is not a function”

Any other ideas??

Thanks!
