0

I have a table with dynamically added rows that need to have different properties for dynamic use, submit, etc. How can I pass their properties without a fixed name, id or class?

The dynamically created element:

<input type="text" name="input1" id="input1" class="input1" onkeyup="foo(this.name, this.value);"/>

The JavaScript function:

foo(this.name, this.value){
    //data handler
};

I can´t rely on static properties for the function, they have to be passed after the element is created.

2 Answers 2

1

Do you tried using foo(this)?

And in function, gets properties.

function foo(node) {
    node.property;
}
Sign up to request clarification or add additional context in comments.

Comments

0

You can add an event listener after the object is created by using:

your_new_object.addEventListener('keyup',foo,false);

1 Comment

This solution isn't cross-browser (not working in IE8 or lower), and the second parameter must be "foo", not "foo()".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.