jason7564
jason7564

Reputation: 1

How can I append the value of an input text into a variable with jQuery?

I tried using:

$("#userInput").appendTo("gList") //The name of my variable is gList

but it didn't work.

Upvotes: 0

Views: 51

Answers (1)

user5548116
user5548116

Reputation:

As i understand this gList this is an array so you have to do next

var gList = []; 
// ... do some job
var inputValue = $("#userInput").val();  //console.log(inputValue)
gList.push(inputValue); // console.log(gList)

If gList is a string you can concatenate it gList = gList + inputValue

Thanks

Upvotes: 1

Related Questions