# Monitoring the changes in \<div\> tag

**URL:** <https://www.ruby-forum.com/t/monitoring-the-changes-in-div-tag/186400>\
**Category:** Rails\
**Created:** [April 6, 2010, 2:36pm UTC](https://www.ruby-forum.com/t/monitoring-the-changes-in-div-tag/186400 "2010-04-06T14:36:56Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![loganathanbk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/51bf81/32.png) [@loganathanbk](https://www.ruby-forum.com/u/loganathanbk)\
**Post date:** [April 6, 2010, 2:36pm UTC](https://www.ruby-forum.com/t/monitoring-the-changes-in-div-tag/186400/1 "2010-04-06T14:36:56Z")

</div>

Dear friend,

I need a suggestion for the following requirement:

I have a

 tag as follows: 

I used the link\_to\_remote and using that updated the response in the

.

We have observe\_fields for the tags like using the “Onchange”  
event and  
can track the changes happening in the tag.

Do we have the same kind of method for

 tag to get track the  
changes happening in the 
 tag.

I can also use the periodically\_call\_remote to achieve my requirement.  
But it is not efficient. I should make a Ajax call only when there is  
some updation happening in the

 tag.

---

<div class="post-metadata">

**Author:** ![loganathanbk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/51bf81/32.png) [@loganathanbk](https://www.ruby-forum.com/u/loganathanbk)\
**Post date:** [April 6, 2010, 3:24pm UTC](https://www.ruby-forum.com/t/monitoring-the-changes-in-div-tag/186400/2 "2010-04-06T15:24:16Z")

</div>

On 6 April 2010 13:36, Loganathan G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> We have observe\_fields for the tags like using the “Onchange”  
> event and  
> can track the changes happening in the tag.
> 
> Do we have the same kind of method for
> 
> tag to get track the  
> changes happening in the 
> tag.
> 
> I can also use the periodically\_call\_remote to achieve my requirement.  
> But it is not efficient. I should make a Ajax call only when there is  
> some updation happening in the
> 
> tag.

How is something changing in the div tag? Do you mean a change by the  
call from the link\_to\_remote? If so then surely you already know it  
is changing as you are doing it yourself. I must be missing  
something.

Colin

---

<div class="post-metadata">

**Author:** ![loganathanbk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/51bf81/32.png) [@loganathanbk](https://www.ruby-forum.com/u/loganathanbk)\
**Post date:** [April 7, 2010, 6:37am UTC](https://www.ruby-forum.com/t/monitoring-the-changes-in-div-tag/186400/3 "2010-04-07T06:37:42Z")

</div>

Colin L. wrote:

> On 6 April 2010 13:36, Loganathan G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > We have observe\_fields for the tags like using the “Onchange”  
> > event and  
> > can track the changes happening in the tag.
> > 
> > Do we have the same kind of method for
> > 
> > tag to get track the  
> > changes happening in the 
> > tag.
> > 
> > I can also use the periodically\_call\_remote to achieve my requirement.  
> > But it is not efficient. I should make a Ajax call only when there is  
> > some updation happening in the
> > 
> > tag.
> 
> How is something changing in the div tag? Do you mean a change by the  
> call from the link\_to\_remote? If so then surely you already know it  
> is changing as you are doing it yourself. I must be missing  
> something.
> 
> Colin

You misunderstood the concept. Ya the

 is updated by using :update  
in the link\_to\_remote. I want something like observe\_field to monitor  
the changes happening in the 
 tag. Because we can also use  
:complete to get to know the changes happened in the 

But it is for only the particular session. Whereas in the observe\_field,  
it calls the appropriate action whenever changes happened in the  
 tag. The ajax request will go for all the sessions.

Incase of more than one session currently using my application, the link  
clicked in the particular session only will get to use of the :complete.

If any clarifications need revert back me.

---

<div class="post-metadata">

**Author:** ![loganathanbk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/51bf81/32.png) [@loganathanbk](https://www.ruby-forum.com/u/loganathanbk)\
**Post date:** [April 7, 2010, 3:59pm UTC](https://www.ruby-forum.com/t/monitoring-the-changes-in-div-tag/186400/4 "2010-04-07T15:59:03Z")

</div>

Loganathan G. wrote:

> You misunderstood the concept. Ya the
> 
> is updated by using :update  
> in the link\_to\_remote. I want something like observe\_field to monitor  
> the changes happening in the 
> tag. Because we can also use  
> :complete to get to know the changes happened in the 
> 
> But it is for only the particular session. Whereas in the observe\_field,  
> it calls the appropriate action whenever changes happened in the  
> tag. The ajax request will go for all the sessions.
> 
> Incase of more than one session currently using my application, the link  
> clicked in the particular session only will get to use of the :complete.
> 
> If any clarifications need revert back me.

I think you are misunderstanding how observe\_fields works. It does not  
monitor changes in the DOM, rather it attaches event listeners to each  
individual form field.

Take a look at the list of events that are applicable to HTML elements.  
Notice there is no “onchange” event:

> **[HTML DOM Element Object](https://www.w3schools.com/jsref/dom_obj_all.asp)**
>
> W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.

The onchange event is applicable to controls (text boxes, popup lists,  
checkboxes, etc.). The DOM itself doesn’t change, rather it gets changed  
as a result of some other event.

---

<div class="post-metadata">

**Author:** ![loganathanbk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/51bf81/32.png) [@loganathanbk](https://www.ruby-forum.com/u/loganathanbk)\
**Post date:** [April 8, 2010, 1:58pm UTC](https://www.ruby-forum.com/t/monitoring-the-changes-in-div-tag/186400/5 "2010-04-08T13:58:53Z")

</div>

Loganathan G. wrote:

> But my need is to monitor the
> 
> tag. If any updates happen in 
> ,  
> I should make an Ajax Call. How can I do it?
> 
> I think you have your answer. You can’t. It makes no sense based on how  
> this stuff works. You can’t monitor a change in a div tag because there  
> is no event to monitor. You must instead monitor the event that caused  
> the div to change. If the div changes, it is in response to some action  
> (a click event, a load event, a mouse event, etc.). Figure out what  
> event is causing the div to change and do whatever you need to do then.

---

<div class="post-metadata">

**Author:** ![loganathanbk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/51bf81/32.png) [@loganathanbk](https://www.ruby-forum.com/u/loganathanbk)\
**Post date:** [April 8, 2010, 8:34am UTC](https://www.ruby-forum.com/t/monitoring-the-changes-in-div-tag/186400/6 "2010-04-08T08:34:30Z")

</div>

Robert W. wrote:

> Loganathan G. wrote:
> 
> > You misunderstood the concept. Ya the
> > 
> > is updated by using :update  
> > in the link\_to\_remote. I want something like observe\_field to monitor  
> > the changes happening in the 
> > tag. Because we can also use  
> > :complete to get to know the changes happened in the 
> > 
> > But it is for only the particular session. Whereas in the observe\_field,  
> > it calls the appropriate action whenever changes happened in the  
> > tag. The ajax request will go for all the sessions.
> > 
> > Incase of more than one session currently using my application, the link  
> > clicked in the particular session only will get to use of the :complete.
> > 
> > If any clarifications need revert back me.
> 
> I think you are misunderstanding how observe\_fields works. It does not  
> monitor changes in the DOM, rather it attaches event listeners to each  
> individual form field.
> 
> Take a look at the list of events that are applicable to HTML elements.  
> Notice there is no “onchange” event:  
> [HTML DOM Element Object](http://www.w3schools.com/jsref/dom_obj_all.asp)
> 
> The onchange event is applicable to controls (text boxes, popup lists,  
> checkboxes, etc.). The DOM itself doesn’t change, rather it gets changed  
> as a result of some other event.

But my need is to monitor the

 tag. If any updates happen in 
,  
I should make an Ajax Call. How can I do it?

Suggestions welcome…

---

<div class="post-metadata">

**Author:** ![loganathanbk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/51bf81/32.png) [@loganathanbk](https://www.ruby-forum.com/u/loganathanbk)\
**Post date:** [April 8, 2010, 2:47pm UTC](https://www.ruby-forum.com/t/monitoring-the-changes-in-div-tag/186400/7 "2010-04-08T14:47:39Z")

</div>

The only hack I can think about would be to have your own monitor with  
some  
dirty javascript based on a setInterval and compare the innerHTML of the  
div  
with a previous state.  
But Robert’s answer is much safer.

2010/4/8 Robert W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
