xxxxxxxxxx
<!DOCTYPE html>
<html>
<head>
<title>Using the ref attribute</title>
</head>
<body>
<div>
<label for="nameInput">Name:</label>
<input type="text" id="nameInput" />
<button onclick="displayValue()">Submit</button>
</div>
<script>
function displayValue() {
// Getting the value of the input element using the 'ref' attribute
const nameInput = document.getElementById('nameInput').value;
console.log("Name:", nameInput);
}
</script>
</body>
</html>
xxxxxxxxxx
Ref is React hook used as useRef
Refs provide a way to access DOM nodes or React elements created in the render method.