Connecting Tech Pros Worldwide Help | Site Map

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

sjdevnull@yahoo.com
Guest
 
Posts: n/a
#1: Sep 8 '08
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!
Gregor Kofler
Guest
 
Posts: n/a
#2: Sep 8 '08

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


sjdevnull@yahoo.com meinte:
Quote:
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


--
http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie
http://web.gregorkofler.com ::: meine JS-Spielwiese
http://www.image2d.com ::: Bildagentur für den alpinen Raum
RobG
Guest
 
Posts: n/a
#3: Sep 8 '08

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


On Sep 8, 5:08*pm, Gregor Kofler <use...@gregorkofler.atwrote:
Quote:
sjdevn...@yahoo.com meinte:
>
Quote:
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.
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-Eve...Types-complete
Quote:
>

--
Rob
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
#4: Sep 8 '08

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


RobG wrote:
Quote:
On Sep 8, 5:08 pm, Gregor Kofler <use...@gregorkofler.atwrote:
Quote:
>sjdevn...@yahoo.com meinte:
Quote:
>>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.
>
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-Eve...Types-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
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>
SAM
Guest
 
Posts: n/a
#5: Sep 8 '08

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


sjdevnull@yahoo.com a écrit :
Quote:
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[i].innerHTML != '') {
var t = document.createElement('SPAN');
t.innerHTML = mydatas;
u[i].appendChild(t);
}
}
}
}
Quote:
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[i].innerHTML != '' &&
u[i].getElementsByTagName('OBJECT') &&
u[i].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());

--
sm
Gregor Kofler
Guest
 
Posts: n/a
#6: Sep 8 '08

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


RobG meinte:
Quote:
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-Eve...Types-complete
Right. Unfortunately, well, won't work for approx. 80% of the visitors,
though...

Gregor


--
http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie
http://web.gregorkofler.com ::: meine JS-Spielwiese
http://www.image2d.com ::: Bildagentur für den alpinen Raum
Closed Thread


Similar JavaScript / Ajax / DHTML bytes