Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery parse HTML

Tags:

html

jquery

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

like image 727
The87Boy Avatar asked Feb 02 '26 05:02

The87Boy


2 Answers

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

function getCellText($cell)
{
    var value = $cell.find('input.studentno').val();
    console.log(value);
}
like image 173
Matt Ball Avatar answered Feb 03 '26 18:02

Matt Ball


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());
}
like image 22
Rory McCrossan Avatar answered Feb 03 '26 17:02

Rory McCrossan