Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get the value from an event target in js

inside js function I'm receiving event as parameter, how do you get the value of the event target?

function myFn(event){
    ...
    close: function(event){
        var myVal = ... 
        /// should grab from 
        /// event-> arguments -> [0]->target -> property value painted in yellow (abc)        
    }
}

enter image description here

like image 842
user1765862 Avatar asked Jul 13 '16 09:07

user1765862


People also ask

How do you value an event target?

Try: function($event) { const value = $event. target.

What is event target value in JS?

The target event property returns the element that triggered the event. The target property gets the element on which the event originally occurred, opposed to the currentTarget property, which always refers to the element whose event listener triggered the event.

How do I find my event target element ID?

You can use event.target.id in event handler to get id of element that fired an event.


2 Answers

This will work:

(<HTMLInputElement>event.target).value

or

event.target as HtmlInputlement

like image 51
mahipal singh Avatar answered Oct 25 '22 10:10

mahipal singh


Try:

var myVal = event.target.value;
like image 40
Michał Perłakowski Avatar answered Oct 25 '22 10:10

Michał Perłakowski