473,811 Members | 3,123 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

update listener for element?

Hello,

Currently I use setInterval to call a function every 1.5 seconds. The
function checks the content of 6 divs on a page. The content of each
div is retrieved use innerHTML. If the content of the div has changed
since it was last checked (1.5 seconds previous), then I know the div
has been updated, and I need to do something.

My questions is: This seems to be a resource heavy and rather clunky
way of checking if a div has been updated. What I'd really like is to
be able to attach a listener to a div, the listener is triggered when
the div is updated.

Is there anyway of doing this? If not, is there anyway I could improve
my current method?

Many thanks,

Jack Wootton

Jun 21 '07 #1
4 1767
ja*********@gma il.com wrote:
Hello,

Currently I use setInterval to call a function every 1.5 seconds. The
function checks the content of 6 divs on a page. The content of each
div is retrieved use innerHTML. If the content of the div has changed
since it was last checked (1.5 seconds previous), then I know the div
has been updated, and I need to do something.

My questions is: This seems to be a resource heavy and rather clunky
way of checking if a div has been updated. What I'd really like is to
be able to attach a listener to a div, the listener is triggered when
the div is updated.

Is there anyway of doing this? If not, is there anyway I could improve
my current method?
well you could attach function to ajax object itself so it will be
triggered when that object updates div..
Jun 21 '07 #2
On Jun 21, 6:12 am, kaaposc <NO-kaaposc-S...@gmail.comw rote:
jackwoot...@gma il.com wrote:
Hello,
Currently I use setInterval to call a function every 1.5 seconds. The
function checks the content of 6 divs on a page. The content of each
div is retrieved use innerHTML. If the content of the div has changed
since it was last checked (1.5 seconds previous), then I know the div
has been updated, and I need to do something.
My questions is: This seems to be a resource heavy and rather clunky
way of checking if a div has been updated. What I'd really like is to
be able to attach a listener to a div, the listener is triggered when
the div is updated.
Is there anyway of doing this? If not, is there anyway I could improve
my current method?

well you could attach function to ajax object itself so it will be
triggered when that object updates div..
Hello kaaposc,

Thank you for replying, unfortunately I do not understand your
answer. I am not using AJAX.
Please could you elaborate?

Jun 21 '07 #3
On Jun 21, 7:57 pm, "jackwoot...@gm ail.com" <jackwoot...@gm ail.com>
wrote:
Hello,

Currently I use setInterval to call a function every 1.5 seconds. The
function checks the content of 6 divs on a page. The content of each
div is retrieved use innerHTML. If the content of the div has changed
since it was last checked (1.5 seconds previous), then I know the div
has been updated, and I need to do something.
The obvious solution is to have whatever function or functions that
modify the DOM to call your function that should operate when the DOM
is modified.

Failing that, you can use the DOM 2 mutation event interface:

<URL: http://www.w3.org/TR/DOM-Level-2-Eve...-MutationEvent
>
Support is very poor - Firefox 2 & Opera 9 support some of it[1],
Safari 3 a bit more, IE probably very little if any. There is a good
page on events here:

<URL: http://www.howtocreate.co.uk/tutoria...ript/domevents >
A trivial example of having an event fire when a DOM node is
inserted. Try it in one of the browsers named above, it will not work
in IE:

<script type="applicati on/javascript">

// Add a DOMNodeInserted listener
function addME(id){
var el = document.getEle mentById(id);
el.addEventList ener('DOMNodeIn serted', sayHi, true);
}

// Modify the DOM
function modDOM(id) {
var el = document.getEle mentById(id);
el.appendChild( document.create TextNode('blah' ));
}

// Trivial function to call
function sayHi() {alert('hi');}

</script>

<input type="button" value="Set listener" onclick="addME( 'xx');">
<input type="button" value="Modify DOM" onclick="modDOM ('xx');">
<div id="xx">DOM Node to modify<br></div>
1. I suspect new versions of Fx and Opera will support more of it.
--
Rob

Jun 21 '07 #4
On Jun 21, 9:37 am, RobG <r...@iinet.net .auwrote:
On Jun 21, 7:57 pm, "jackwoot...@gm ail.com" <jackwoot...@gm ail.com>
wrote:
Hello,
Currently I use setInterval to call a function every 1.5 seconds. The
function checks the content of 6 divs on a page. The content of each
div is retrieved use innerHTML. If the content of the div has changed
since it was last checked (1.5 seconds previous), then I know the div
has been updated, and I need to do something.

The obvious solution is to have whatever function or functions that
modify the DOM to call your function that should operate when the DOM
is modified.

Failing that, you can use the DOM 2 mutation event interface:

<URL:http://www.w3.org/TR/DOM-Level-2-Eve...-MutationEvent

Support is very poor - Firefox 2 & Opera 9 support some of it[1],
Safari 3 a bit more, IE probably very little if any. There is a good
page on events here:

<URL:http://www.howtocreate .co.uk/tutorials/javascript/domevents>

A trivial example of having an event fire when a DOM node is
inserted. Try it in one of the browsers named above, it will not work
in IE:

<script type="applicati on/javascript">

// Add a DOMNodeInserted listener
function addME(id){
var el = document.getEle mentById(id);
el.addEventList ener('DOMNodeIn serted', sayHi, true);
}

// Modify the DOM
function modDOM(id) {
var el = document.getEle mentById(id);
el.appendChild( document.create TextNode('blah' ));
}

// Trivial function to call
function sayHi() {alert('hi');}

</script>

<input type="button" value="Set listener" onclick="addME( 'xx');">
<input type="button" value="Modify DOM" onclick="modDOM ('xx');">
<div id="xx">DOM Node to modify<br></div>

1. I suspect new versions of Fx and Opera will support more of it.

--
Rob
Hello Rob,

This is great thank you. I cannot use method 1, since I am actually
listening for an update on a div element that is not written by me. I
am writing a Fireffox extension, and need to listen for divs on a
specific page in a tab. When those divs are updated, the extension
needs to do something. So my idea is to use the 3nd method you
describe, to listen for the divs being updated. My extension code
will then be notified that an update has occurred. Is this correct?

Jun 22 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3744
by: Cherrish Vaidiyan | last post by:
sir, I have a small error in Listener configuration.I have two system with a database in each. I am using Red Hat 9 and Oracle 9i. so i shall anme the database and system. system 1 - node2 system 2 - node3 database - apple database - intel i have installed Oracle on 'node3' by copying the files and then creating a new database in it. Now i want to configure listener. I
3
694
by: Bill | last post by:
When vb6 Winsock.RemoteHost is set to "127.0.0.1", c# socket listener cannot hear connect request (my old vb6 winsock listener could hear it...). Why doesn't this work, and is there a work around I can make on the C# side to hear the connect request? -Bill (don't reply by e-mail, the address is a fake) ______________________________ Steps to reproduce: Start the C# Listener
2
1457
by: Oliver Block | last post by:
Hi, I am facing a problem with the occurance of click and dblclick events. Given: a table that has n row and m cols, SOME of the cells contain a div-element. ALL td-elements have an eventhandler like <td ... ondblclick="handle_dblck('k') ...> (k is the number of the cell values: 1, 2, 3, x). ALL div-elements have an eventhandler <div ... ondblclick="handle_clk(this)" ...>.
6
6863
by: Jeremy | last post by:
I want each instance of an object to be able to listen for input events. When the event occurs, a method of the object should be called, such that "this" is in scope and refers to the object instance. Is this possible? Example: function MyConstructor(element) {
5
38839
by: mivey4 | last post by:
Hi, First off, I am aware that this is a very heavily documented error and I have done my homework for throughly researching probable causes before deciding to post my problem here. At this point, I believe another set of eyes on the issue is merited. I am a MSSQL DBA and somewhat new to ORACLE; but I have read the administrators manual having a basic thorough level of knowledge (Tho' I am still learning) and understanding of how to...
6
1684
by: moondaddy | last post by:
In a wpf app using c#, is it possible to somehow attach a listener or hook into the IsMouseOver property so when ever it's value changes, a method could be notified? -- moondaddy@newsgroup.nospam
6
7530
by: Gregor Kofler | last post by:
I'm trying to "detect" a keydown event in a DIV. The idea have a keydown listener attached to document and forward the event to the div. (I've searched the web, but it was impossible to handle the noise on this topic.) I've tried a simple prototype in Firefox and it seems to work. function forward(e, elem) { var f, p;
1
2907
by: Gregor Kofler | last post by:
Setting the tabIndex property an element makes it focusable and attached key listeners respond. Or so it seems... This procedure works in - from what I've tested - IE6+, FF, Opera. However, Safari and Chrome (and perhaps others) fail to respond, obviously myElement.focus() can be called, but shows no further effect. One possibility might be a listener attached to the document, which then redirects the event to the "focused" element -...
0
10662
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10416
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10138
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9215
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7676
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6897
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5702
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3881
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3028
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.