Change your line of code js
to the following:
var teste = $("#exemplo").html();
Would look like this:
var teste = $("#exemplo").html();
alert(teste);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<td id='exemplo'>VALOR EXEMPLO 1</td>
<td id='exemplo1'>VALOR 2</td>
</tr>
</table>
First, the call of the event of the JQuery
$("#exemplo").val()
refers to the attribute value
of some element, where the values of the elements are usually stored, but their element in question is actually a td
(structure of the body of a table) which, besides everything, also does not have an attribute value
native, to take its value, the certain semantically would be to put another element inside it, for example a span
or a label
, that would look something like this: <td><label id='exemplo' value='VALOR EXEMPLO 1'>VALOR EXEMPLO 1</label></td>
, so your command line JQuery
nor would need to be changed. But this will go according to each...
Structuring the way you want, the element td
just "write" on the screen what is contained in it, ie the type of element td
does not have the attribute natively value
.
To take the content/value contained within a td
, you should use the event JavaScript
innerHTML();
that in JQuery
is equivalent to the event HTML();
worked perfectly for what I wanted, thank you very much
– Matheus Rocha