3

I have a simple function, that looks like this

var getCellText = function ($cell) {
  var html = $cell.html();
  $(html).find("input").each(function () {
    alert(this.value);
  });
}

The HTML could look like this

<input class="lineno" name="lineno" value="4109375" type="hidden">
<input onchange="Time.UpdateLine(this, 'studentno', this.value, '4109375');" class="studentno" value="2088" type="text">

I need to get the value of the studentno input tag (and I can ignore the input called lineno).

How can I do that, as you can see, I have already given it a try

3 Answers 3

7

You're overcomplicating things. Don't use .html(), do use .val().

function getCellText($cell)
{
    var value = $cell.find('input.studentno').val();
    console.log(value);
}
Sign up to request clarification or add additional context in comments.

Comments

1

Assuming the $cell variable is a jQuery object containing a parent element of .studentno, this will work:

var getCellText = function ($cell) {
    alert($(".studentno", $cell).val());
}

Comments

0

You could try this:

$('input.studentno',html).each(function () {
    alert($(this).val());
});

1 Comment

Yeah I'm not sure what you mean by get rid of the .html() bit.

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.