PhoxKiD PhoxKiD - 1 year ago 144
Javascript Question

how to get value of one of the input elements from the same class?

Here's my snippet.

Is there any other way other than appending event listener to every element of the class?

I would like to avoid loops if possible.

Answer Source

I couldn't add comment to Jason Cemra.

In addition to His/Her answer the target element as required by PhoxKiD is the input with the class 'inp'. So place a condition

document.getElementById("parent").addEventListener("keyup", function (event){
    if( == 'inp') {
        //your code
    else{  //for other inner elements
        event.preventDefault(); //prevents the default action
        event.stopPropagation(); //stop bubbling up
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download