Link to home
Start Free TrialLog in
Avatar of cerub
cerub

asked on

Access a dynamically created element

Hello,

We need to access dynamically created elements on the client side. We would like to do that by using their IDs.

Currently, we can achieve this via the Sys.Application._components node.

Any other viable suggestions?

$Find can be used but we don't know the ID of the elements.

getElementsByTagName wouldn't yield the right names since the objects themselves aren't rendered (CollapsedPanelExtender).

What other means are there to access the right ID other than using Sys.Application.getComponents() ????

Thanks a bunch.
Avatar of leakim971
leakim971
Flag of Guadeloupe image

If you put it in a unique "container", for example a div with a specific ID that you know, you know the child of this div is your object.
Avatar of cerub
cerub

ASKER

But wouldn't the child object's ID change in an arbitrary way as well? I would have to somehow retrieve the "new" ID of the DIV as well. What do you think?
I don't you really need an ID. Generaly we need to get a référence on an object. Once you get this reference you can get its ID easily. The div should be in your page. You know its ID. You put your dynamic object inside.
Avatar of cerub

ASKER

"Generaly we need to get a référence on an object. Once you get this reference you can get its ID easily."

Could you possibly provide an example reference, please?
var myRef = document.getElementById("theDivIdIKnow").childNodes[1];

Open in new window


try 0 instead 1 too
SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cerub

ASKER

Don't get me wrong but you still don't seem to know the names of the elements. You iterate them in order to learn their names.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cerub

ASKER

Thank you! It seems there are two main ways of looking at this problem so I think it is only fair to split the points.

Thanks for the help.
>Don't get me wrong but you still don't seem to know the names of the elements.
The question is : Do you really need the name ? Or do you need a reference to work with the objects ?

>You iterate them in order to learn their names.
No iteration in my code, we get the first node having a tag... and I'm not sure a function like $Find don't use in its black chamber one loop (or more) or something not linear.