Home:ALL Converter>How to get the id attribute of a dynamically-generated element?

How to get the id attribute of a dynamically-generated element?

Ask Time:2012-10-30T14:08:24         Author:Arrow

Json Formatter

How can I get the id attribute of a dynamically generated element when you don't know it's id? I am wanting to setup some eventListeners for about 2000 Checkbox's on a page.

I know I could call a function from within the element:

<input type="checkbox" id="{databaseResult.Value}" onclick="someFunction(this)" />

But I'm not allowed to use JavaScript, or references to it in my HTML. Pure JavaScript (or a language that compiles to it) is my only option.

The code I already have for some elements where I do know the id, is:

var tb = <HTMLInputElement>document.getElementById("tbox");

if(tb.addEventListener("", function (e) {
    sayHello(tb.value);
}, false));

Author:Arrow,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/13133571/how-to-get-the-id-attribute-of-a-dynamically-generated-element
yy