0

I can easily get the last line in a div by using;

 var last_line = $canvas
                       .contents()
                       .filter(function () {
                           return !!$.trim(this.innerHTML || this.data);
                       })
                       .last();
alert(last_line.text());

Now I want to replace the last line only. The text within the div will become quite lengthy over time and I don't want to replace the whole div contents each time, just the last line.

griegs
  • 22,294
  • 32
  • 120
  • 203

1 Answers1

2

You can use jQuery's replaceWith function:

var last_line = $canvas
                       .contents()
                       .filter(function () {
                           return !!$.trim(this.innerHTML || this.data);
                       })
                       .last().replaceWith('<tag>Content to replace it with</tag>');

Documentation: http://api.jquery.com/replaceWith/

scrowler
  • 23,965
  • 9
  • 60
  • 90