Вопрос

Firstly I have a form, this is part from my form code:

<td class="td1" width="15%" id="td00">abc</td>
<td class="td1" width="15%" id="td01">efg</td>

from jQuery, I want pass the value of the td to my server via ajax.

If I use:

var name=$('#td00').val();

I get an empty value, if this is not a table but a text input, I can get value like this, but now it not working in table.

Это было полезно?

Решение

You need to use .text() or .html()

var name=$('#td00').text();
  • .html() will get the html content of the element
  • .text() will get the text content of the element
  • .val() works for <input/> <select/> <textarea/> .It gets the property value of those elements.

Documentation

  1. .Val()

  2. .text()

  3. .html
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top