How to get a values of text box dynamically using jQuery

scripts
#1

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

#2

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

#3

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
#4

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