0

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?

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.