SephMerah
SephMerah

Reputation: 1

Issue when accessing the text of an element

HTML:

<table>
  <tr>
    <td>wddsa</td>
    <td>dffs</td>
  </tr>
</table>

JavaScript:

$('tbody tr').each(function() {
    name2 = $(this).children("td:first").text;
    alert(name2);
});

Returns a bunch function and jquery code. Possibly from jquery.min. What is wrong here?

Upvotes: 0

Views: 31

Answers (1)

JCOC611
JCOC611

Reputation: 19759

You are accessing the actual function, rather than executing it. (.text is a function, not a variable, so you need to execute it to get its return value .text()).

name2 = $(this).children("td:first").text();

Upvotes: 1

Related Questions