How to tell when an li item is inserted into a ul?

S

sjdevnull

Is there some event I can monitor to tell either if a new li has been
created as a child of a certain ul, or to tell if the ul contents have
changed in general (so that I can walk the children looking for new
items)?

It's a sort of odd request, but I'm using a 3rd-party filebrowser
library that uses Flash to implement a multiselect-capable file upload
tool. The browser append children to a UL, but I'd also like to
include a bit of metadata with each file that's being uploaded.

I've got several workarounds in mind, but I'm curious as to the
original question.

If this is not the appropriate newsgroup for this kind of question, I
apologize and please let me know if you have a suggestion for a better
forum.

Thanks for your time!
 
G

Gregor Kofler

(e-mail address removed) meinte:
Is there some event I can monitor to tell either if a new li has been
created as a child of a certain ul, or to tell if the ul contents have
changed in general (so that I can walk the children looking for new
items)?

No.

Gregor
 
T

Thomas 'PointedEars' Lahn

RobG said:
Well, strictly, yes, there is *some* event.

W3C DOM 3 Event interface includes DOMNodeInserted and
DOMNodeInsertedIntoDocument, plus "removed" equivalents. However, not
many browsers support that.

<URL: http://www.w3.org/TR/DOM-Level-3-Events/events.html#Events-EventTypes-complete

As a fallback, one can use self-issuing window.setTimeout() calls or
one window.setInterval() call to watch for changes in the subtree regularly.

The cross-browser reaction time cannot be smaller than 10 ms, then, and it
is likely to be greater (because the system timer tick interval may be
greater, other tasks/threads might interfere, and the test takes time, too).


PointedEars
 
S

SAM

(e-mail address removed) a écrit :
Is there some event I can monitor to tell either if a new li has been
created as a child of a certain ul, or to tell if the ul contents have
changed in general (so that I can walk the children looking for new
items)?

It's a sort of odd request, but I'm using a 3rd-party filebrowser
library that uses Flash to implement a multiselect-capable file upload
tool. The browser append children to a UL, but I'd also like to
include a bit of metadata with each file that's being uploaded.

function includeDatas(ul_Id, mydatas) {
var u = document.getElementsById(ul_id);
if (u) {
u = u.getElementsByTagName('LI');
if(u.length>0) {
for(var i=0, n=u.length; i<n; i++)
if(u.innerHTML != '') {
var t = document.createElement('SPAN');
t.innerHTML = mydatas;
u.appendChild(t);
}
}
}
}
I've got several workarounds in mind, but I'm curious as to the
original question.

var doesItFlash = false;
function flashInserted() {
var u = document.getElementsByTagName('LI');
if(u.length>0) {
for(var i=0, n=u.length; i<n; i++)
if( u.innerHTML != '' &&
u.getElementsByTagName('OBJECT') &&
u.getElementsByTagName('OBJECT').length>0) {
doesItFlash = true;
}


or :

var C = { old: 0, recent: 0 };
function changedContent() {
var d = document.getElementsByTagName('*');
if(C.old == 0) C.old = d.length;
C.recent = d.length;
if( C.old == C.recent ) return false;
C.old = C.recent;
return true;
}
window.onload = changedContent;

test :
alert('is there more elements ? '+changedContent());
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top