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

This is a discussion on How to tell when an li item is inserted into a ul? within the Javascript forums in Programming Languages category; 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 ...

Go Back   Application Development Forum > Programming Languages > Javascript

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 09-08-2008, 01:15 AM
sjdevnull@yahoo.com
Guest
 
Default How to tell when an li item is inserted into a ul?

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!
Reply With Quote
  #2  
Old 09-08-2008, 03:08 AM
Gregor Kofler
Guest
 
Default Re: How to tell when an li item is inserted into a ul?

sjdevnull@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
Reply With Quote
  #3  
Old 09-08-2008, 04:33 AM
RobG
Guest
 
Default Re: How to tell when an li item is inserted into a ul?

On Sep 8, 5:08*pm, Gregor Kofler <use...@gregorkofler.at> wrote:
> 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
Reply With Quote
  #4  
Old 09-08-2008, 04:50 AM
Thomas 'PointedEars' Lahn
Guest
 
Default Re: How to tell when an li item is inserted into a ul?

RobG wrote:
> On Sep 8, 5:08 pm, Gregor Kofler <use...@gregorkofler.at> wrote:
>> 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>
Reply With Quote
  #5  
Old 09-08-2008, 05:05 AM
SAM
Guest
 
Default Re: How to tell when an li item is inserted into a ul?

sjdevnull@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
Reply With Quote
  #6  
Old 09-08-2008, 06:16 AM
Gregor Kofler
Guest
 
Default Re: How to tell when an li item is inserted into a ul?

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
Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 04:08 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.