I have a <table>
with a <td>
where I would like to replace the text - using javascript.
<table class="table">
<tbody>
<tr>
<td id="53ffaf3e436872c452020000">
2014-08-16T11:00:00.000+02:00
</td>
</tr>
</tbody>
</table>
I receive from the server a new_dates
object of key
/ value
pairs that I loop through:
Coffeescript version:
last_dates.map (last_date) ->
for key of last_date
console.log key + " has the date: " + last_date[key] # 53ffb262436872c499b90f00 has the date: 2014-08-16T11:00:55.000+02:00
$("##{key}").text = "#{last_date[key]}"
Javascript version:
last_dates.map(function(last_date) {
var key, _results;
_results = [];
for (key in last_date) {
console.log(key + " has the date: " + last_date[key]); // 53ffb262436872c499b90f00 has the date: 2014-08-16T11:00:55.000+02:00
_results.push($("#" + key).text = "" + last_date[key]);
}
return _results;
});
The above code is supposed to find all the id's from key
's, and replace their text values with value
's. My code, however, does not work. What am I doing wrong?
jQuery.text
is a function. You're trying to use it as a property. Try this instead:
$("#" + key).text(last_date[key]);
You don't need to prepend an empty String - anything you insert as a text node will be converted into a String.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.