Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

apply function to all elements with a class name

/*
The getElementsByClassName returns a array of elements (2 in your example),
so you'll have to loop through it and add the onclick event.
To access the current button inside the onclick event handler, use this.
You cannot pass whatever parameters you want to the function because its signature is fixed.
It gets passed a reference to the event itself, not the clicked element,
so the name clicked_button is deceiving. We usually call that parameter event,
or e for short. You can access the element using event.target, but using this is just easier.

*/

var value;
var buttons = document.getElementsByClassName('button');

for (var i = 0; i < buttons.length; i++) {
  buttons[i].onclick = selectValue;
}

function selectValue() {
  value = this.value;
  console.log(value);
}
Comment

PREVIOUS NEXT
Code Example
Typescript :: if confidence level increases what happens to width 
Typescript :: how many elements can be stored in an array 
Typescript :: typescript declare array of maps 
Typescript :: multer s3 access denied 
Typescript :: Jane and the Frost Giants "c++" 
Typescript :: program that will convert input number to farenheit to its equivalent measure in celsius for python 
Typescript :: its getting abort when im trying to open the webcame using opencv 
Typescript :: react-stripe-elements hidePostalCode 
Typescript :: vim show different parts of same file 
Typescript :: cheapest houses in usa 
Typescript :: What are the components of the environment? Explain it along with the examples class 6 
Typescript :: Scroll,Position 
Typescript :: nativescript alert 
Typescript :: res.write prints html tags as text in express 
Typescript :: java sort list by attribute 
Typescript :: spread types may only be created from object types firebase 
Typescript :: middleware in endpoint controller routing-controllers 
Typescript :: how to checka query to return User whose first name starts with R or last name starts with D in django 
Typescript :: code converter from javascript to typescript 
Typescript :: TypeError: agent_go() takes 0 positional arguments but 1 was given 
Typescript :: number square n times in typescript 
Typescript :: selenium components 
Typescript :: distance between two lat long points google maps api 
Typescript :: land features created by plates moving toward each other 
Cpp :: how to convert string to wchar_t in c++ 
Cpp :: c++ - include all libraries 
Cpp :: c++ how to loop through a vector but not the last element 
Cpp :: torch cuda is available 
Cpp :: c++ colour text 
Cpp :: merge images opencv c++ 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =