0

Is it possible to select this input with jquery without assigning an id or class?

<input type="hidden" name="nOfAnswers[]" value="2">

At the moment I use:

    $nOfAnswers = $table.find("input[name*='nOfAnswers[]']");

But when I print it:

    console.log($nOfAnswers.html());

It prints a blank line to the console.

1
  • 1
    Your code is working as expected. What do you expect $nOfAnswers.html() to print? (PS. .html() is using .innerHTML internally.) Try to console.log($nOfAnswers.length); to see if the selector is even working. Commented Oct 8, 2014 at 19:09

2 Answers 2

3

It should be: $nOfAnswers.val()

Sign up to request clarification or add additional context in comments.

Comments

0

With jQuery you can try

$nOfAnswers = $("input[name='nOfAnswers'").val()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.