| | |
Detect div change
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
My immediate thought is that you could md5(innerHTML onload) your div's and store the reult (as a JavaScript variable). Then, whenever you need to know if the div's contents have changed, compare md5(current innerHTML) with the stored md5.
Md5 would be a cheap way to store a representation of innerHTML without needing to store inneHTML itself. Even cheaper would be
Of course, with these techniques no event will fire as it would if onchange were available so you would need to code it somehow differently.
If you don't know what md5 is, then try an internet search (Google, Alta Vista etc).
Airshow
Md5 would be a cheap way to store a representation of innerHTML without needing to store inneHTML itself. Even cheaper would be
innerHTML.length but a subsequent comparison would be significantly less reliable unless you can make length assumptions about your div's contents.Of course, with these techniques no event will fire as it would if onchange were available so you would need to code it somehow differently.
If you don't know what md5 is, then try an internet search (Google, Alta Vista etc).
Airshow
50% of the solution lies in accurately describing the problem!
Airshow, the problem still...
Right, done.
Now I need to compare length after the div content change?
How to?
window.onload = function () { someVar = document.getElementById('myDiv').innerHTML.length; }; //or md5 like you suggested. Right, done.
Now I need to compare length after the div content change?
How to?
Last edited by peter_budo; Aug 9th, 2009 at 8:13 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Zeg,
That is indeed your problem.
Because
That is indeed your problem.
Because
onchange is not available, you have no alternative than to perform the comparison :- in response to some other event (eg. user event(s) or by setInterval polling).
- synchronously, in each piece of code that can change the contents of your div.
Last edited by Airshow; Aug 9th, 2009 at 8:30 am.
50% of the solution lies in accurately describing the problem!
•
•
Join Date: Aug 2007
Posts: 165
Reputation:
Solved Threads: 18
•
•
•
•
Hi people,
How to I can detect if a div was changed after the page loaded?
E.g. by innerHTML function.
ps: onChange not is valid for tag div. Reference here on w3c.
Thanks!
If your program is less deterministic, you'll have to use a background function that periodically checks all your divs of interest. If you are clever, you may be able to add an md5() method to each div; this method returns the md5sum of the innerHTML content; you should also add the original_md5sum value to each div. (Remember, this is ECMAScript: highly flexible. The DOM isn't necessarily etched in stone.)
So, onload:
- add static original_md5sum to each div of interest of the respective innerHTML content
- start a function in the background that periodically checks all the divs of interest for change. It either computes the div's innerHTML md5sum compares that with the static original sum.
For background functions, look into interval timers.
Last edited by Fest3er; Aug 9th, 2009 at 3:17 pm.
![]() |
Similar Threads
- Detect height / set height (JavaScript / DHTML / AJAX)
- Maintain Div Postion on Refresh (JavaScript / DHTML / AJAX)
- Varible change Detection (Python)
- Detect data change in datagrig (VB.NET)
- unable to get into BIOS to change my priority boot disk!!cant reformat my computer!!! (Windows NT / 2000 / XP)
- Need to Preload many Images (and show a wait screen) (JavaScript / DHTML / AJAX)
- ofstream - detect if file has been deleted between open and close (C++)
- What exploit are they using? (Web Browsers)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: JavaScript Custom Object Scope: Why does it work?
- Next Thread: Javascript Scroll Text
| Thread Tools | Search this Thread |
acid2 ajax ajaxexample ajaxjspservlets array browser bug captchaformproblem cart checkbox child class close codes createrange() css cursor date debugger decimal dependent design disablefirebug dom dropdown editor element embed engine enter error events explorer ext file firefox focus form forms frameworks getselection google gxt hiddenvalue highlightedword hint html ie7 ie8 iframe images index internet java javascript javascripthelp2020 jquery jsf jsfile jsp jump libcurl listbox maps masterpage math media menu mp4 object onmouseoutdivproblem onmouseover onreadystatechange parent paypal pdf php position post problem programming progressbar prototype redirect runtime safari scale scriptlets scroll search security shopping size software toggle unicode w3c web wysiwyg \n





