How to get a values of text box dynamically using jQuery

How to get a values of text box dynamically when click on button using jQuery and its values stored in variable

Is the value to be stored in a variable, or is the button value obtained from a stored variable?

It is recommended to stay away from jQuery these days.

How you obtain the input value, can easily be done without needing to involve jQuery.

<input id="input" value="some value">
<button id="button">Get value</button>
const button = document.querySelector("#button");
button.addEventListener("click", function () {
  const input = document.querySelector("#input");
  const value = input.value; // "some value"
1 Like

However having said that, the same thing done using the jQuery library is:

const button = $("#button");
button.on("click", function () {
  const input = $("#input");
  const value = input.val(); // "some value"
1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.