[jquery]How to select specific form and class and ID together

2905 views jquery

How can I select the element with id "list" in my code?


My HTML code:

  <form id="form1">
    <div class="form-group">
      <textarea class="form-control text-center border-primary" id=list rows="3"></textarea>
      <button type="button" id="button" onclick="send();" class="btn btn-dark">Start</button><br>


My jQuery code :

I'm trying to select the element with id "list" using jQuery...

var line = $('#form1 .form-group #list').val();

But I get the following error:

"TypeError: line is undefined"

answered question

1 Answer


I take it you want to select the value of the textarea. Your id, first of all isn't quoted. Second, you made a spelling error in your id.

So either change this line

<textarea class="form-control text-center border-primary" id=lista rows="3"></textarea>


<textarea class="form-control text-center border-primary" id="list" rows="3"></textarea>

Other than that it is not needed to cascade your search like that if you use an ID. Simply: $(#list).val() should be enough.

posted this

Have an answer?


Please login first before posting an answer.