By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,687 Members | 1,806 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,687 IT Pros & Developers. It's quick & easy.

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

P: n/a
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!
Sep 8 '08 #1
Share this Question
Share on Google+
5 Replies


P: n/a
sj*******@yahoo.com 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
--
http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie
http://web.gregorkofler.com ::: meine JS-Spielwiese
http://www.image2d.com ::: Bildagentur für den alpinen Raum
Sep 8 '08 #2

P: n/a
On Sep 8, 5:08*pm, Gregor Kofler <use...@gregorkofler.atwrote:
sjdevn...@yahoo.com 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.
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
>

--
Rob
Sep 8 '08 #3

P: n/a
RobG wrote:
On Sep 8, 5:08 pm, Gregor Kofler <use...@gregorkofler.atwrote:
>sjdevn...@yahoo.com 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.

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>
Sep 8 '08 #4

P: n/a
SAM
sj*******@yahoo.com 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[i].innerHTML != '') {
var t = document.createElement('SPAN');
t.innerHTML = mydatas;
u[i].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[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
Sep 8 '08 #5

P: n/a
RobG meinte:
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
Sep 8 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.