What is a get elements by class name:-
This will returns an array-like object of all child elements which have all of the given class names
We can read all values using loop.
Code
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<input type="text" value="20" class='txt1'>
<input type="text" value="100" class='txt1'>
<button type="button" onclick="get_txt();">Get Textbox value</button>
<script>
function get_txt()
{
var x = document.getElementsByClassName("txt1");
alert(x[0].value);
alert(x[1].value);
}
</script>
</body>
</html>
No comments: