# RJS error: TypeError: element is null

**URL:** <https://www.ruby-forum.com/t/rjs-error-typeerror-element-is-null/185354>\
**Category:** Rails\
**Created:** [March 18, 2010, 4:33pm UTC](https://www.ruby-forum.com/t/rjs-error-typeerror-element-is-null/185354 "2010-03-18T16:33:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![salil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c89c15/32.png) [@salil](https://www.ruby-forum.com/u/salil)\
**Post date:** [March 18, 2010, 4:33pm UTC](https://www.ruby-forum.com/t/rjs-error-typeerror-element-is-null/185354/1 "2010-03-18T16:33:36Z")

</div>

Hi All,

I got RJS error: TypeError: element is null while using ajax.

I used in view

\<%= periodically\_call\_remote(:url=\>{:action=\>‘get\_user\_list’, :id=\>‘1’},  
:frequency =\> ‘5’) %\>

in controller

```
  render :update do |page|
    page.replace_html 'chat_area', :partial => 'chat_area', :object

```

=\> [@chats, @user] if @js\_update  
end

in partial chat\_area

\<% if !@chats.blank? && !show\_div(@chats).blank?%\>  
\<% show\_div\_id=show\_div(@chats) %\>  
\<% for chat in @chats %\>

```
    <% form_remote_for(:chat, :url => {:controller=>'chats',

```

:action=\>‘create’, :id=\>1}, :html=\>{:name =\> “form\_#{chat.id}”},  
:complete=\>“resetContent(’#{chat.id}’);”) do |f| %\>

  
\<%= f.hidden\_field :sessionNo, :value=\>chat.sessionNo %\>  
\<%= f.text\_area :chatContent, :id=\>  
“chatContent\_field\_#{chat.id}”, :cols=\>“100”, :rows=\>“6”,  
:onKeyPress=\>“return submitenter(this,event);” %\>  

  
  
\<% end %\>  

```
</div>

```

\<% end %\>

\<% else %\>

  
  

  
\<% end %\>

Any help is appreciated.

Regards,

Salil G.

---

<div class="post-metadata">

**Author:** ![salil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c89c15/32.png) [@salil](https://www.ruby-forum.com/u/salil)\
**Post date:** [March 18, 2010, 4:50pm UTC](https://www.ruby-forum.com/t/rjs-error-typeerror-element-is-null/185354/2 "2010-03-18T16:50:07Z")

</div>

On 18 March 2010 15:33, Salil G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> render :update do |page|
> page.replace_html 'chat_area', :partial => 'chat_area', :object
> 
> ```
> 
> =\> [@chats, @user] if @js\_update  
> end

I believe this is expecting to find a div with id chat\_area to  
replace. I do not see this div in the code below, though I may be  
just not be seeing it.

Colin

---

<div class="post-metadata">

**Author:** ![salil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c89c15/32.png) [@salil](https://www.ruby-forum.com/u/salil)\
**Post date:** [March 19, 2010, 5:39am UTC](https://www.ruby-forum.com/t/rjs-error-typeerror-element-is-null/185354/3 "2010-03-19T05:39:57Z")

</div>

> I believe this is expecting to find a div with id chat\_area to  
> replace. I do not see this div in the code below, though I may be  
> just not be seeing it.
> 
> Colin  
> Following div is present on my index.rhtml

 \<%= render :partial=\>'chat\_area' %\>

I don’t know what is the problem with this div or partial’s content  
while using same technique i am updating my other div’s

Regards,

Salil G.

---

<div class="post-metadata">

**Author:** ![salil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c89c15/32.png) [@salil](https://www.ruby-forum.com/u/salil)\
**Post date:** [March 19, 2010, 9:46am UTC](https://www.ruby-forum.com/t/rjs-error-typeerror-element-is-null/185354/4 "2010-03-19T09:46:54Z")

</div>

On 19 March 2010 07:04, Salil G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi All,
> 
> I find it out why it happens because I didn’t close div above the  
> “chat\_area” properly. the only thing i did isclose the div and it works  
> like a magic, neways thanks to all

I suggest installing the html validator add-in to Firefox and that  
will check the html of your pages as you develop them. This would  
have shown your missing /div immediately.

Alternatively you can paste the html of the page into the w3c html  
validator for checking but this is much less convenient.

Colin

---

<div class="post-metadata">

**Author:** ![salil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c89c15/32.png) [@salil](https://www.ruby-forum.com/u/salil)\
**Post date:** [March 19, 2010, 8:04am UTC](https://www.ruby-forum.com/t/rjs-error-typeerror-element-is-null/185354/5 "2010-03-19T08:04:59Z")

</div>

Hi All,

I find it out why it happens because I didn’t close div above the  
“chat\_area” properly. the only thing i did isclose the div and it works  
like a magic, neways thanks to all

Reagrds,

Salil G.
