Change your line of code js
to the following:
var teste = $("#exemplo").html();
It 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><tdid='exemplo'>VALOREXEMPLO1</td><tdid='exemplo1'>VALOR2</td></tr></table>
First,theeventcallofJQuery
$("#exemplo").val()
refers to the value
attribute of some element, where the element values are usually stored, but its element in fact is td
( structure of the body of a table) which, after all, does not have a value
native attribute, to get its value, semantically correct would be to put another element inside it, for example a span
or a label
which would look something like this: <td><label id='exemplo' value='VALOR EXEMPLO 1'>VALOR EXEMPLO 1</label></td>
, so your command line JQuery
would not even need to be changed. But this goes according to each one ...
By designing as you wish, the td
element only "writes" on the screen what is contained in it, ie the td
element type does not natively have the value
attribute.
To get the content / value contained within a td
, you should use the event JavaScript
innerHTML();
which in JQuery
is equivalent to the HTML();
event