I have a problem with an Input.
here's my html/php code :
$dotation = ($ig["dotation"]) ? $ig["dotation"]: '<input type="text" class="datepickerIG" name="igDota" size="8" value="test"/>';
$bo .= '<tr style="background-color: black;">
<td class="dot">' . $dotation . '</td>
<td class="modif" ref="' . $ig["id"] . '"><a href="#">Modifier</a></td>
here's my js code :
var dot_cha = $(this).parent().find('.dot').val();
my question is, why var dot_cha is always empty ?! when I use .html insteed of .val, I get the right so, where's my error ?
Thanks.
.val() grabs the value attribute of a input-element. ".dot" is a td and doesn't have a value-attribute.
What exactly is it you want dot_cha to be? If its the input you are after, this would work.
If it is the text of the td .html() or .text() will give you this.
val
retrieves the value ofinput
and other tags which have this attribute. In your case,.dot
is the class of a table row which has no attributevalue
... So you have to use.text()
or.html()
.val()
is to be used with form elements (such asinput
,textarea
etc...), not with elements.You need to get the
innerHTML
orinnerText
of the element.Something like:
Though you need to ensure you have one element - as you may be getting a collection of elements.
From the jQuery API documentation:
val
is used on form elements. Since.dot
is atd
element (which is not a form element) usingval
on it will not work. To get the contents of any element other than a form element, use.html
or.text
From the docs:
The doc here says
You're right .html works since in your case you have a td, and you should use
Hope it helps