Note that there are some explanatory texts on larger screens.

plurals
  1. POAppend text in table while retaining existing data
    primarykey
    data
    text
    <p>I am working on a app that plays music files. Part of the app lists tracks available to be played in a rails table:</p> <pre><code>&lt;table class="table table-hover"&gt; &lt;thead&gt; &lt;tr&gt; &lt;th&gt;#&lt;/th&gt; &lt;th&gt;Title&lt;/th&gt; &lt;th&gt;Featured Artist&lt;/th&gt; &lt;th&gt;Length&lt;/th&gt; &lt;th&gt;Size&lt;/th&gt; &lt;th&gt;&lt;/th&gt; &lt;th&gt;&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;% album.tracks.each do |t| %&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;%= t.track_number.to_s.rjust(2, '0') %&gt;&lt;/td&gt; &lt;td&gt;&lt;%= t.title %&gt;&lt;/td&gt; &lt;td&gt;&lt;%= t.artists.map{ |a| [a][0].name }.join(", ") %&gt;&lt;/td&gt; &lt;td id="time"&gt;&lt;%= "#{((t.length) / 60)}:""#{(t.length % 60).to_s.rjust(2, '0')}" %&gt;&lt;/td&gt; &lt;td&gt;&lt;%= "#{t.size} MB" %&gt;&lt;/td&gt; &lt;td&gt; &lt;div class="btn-group btn-group-hover pull-left" data-id="&lt;%= t.id%&gt;" data-url="&lt;%= t.track_path%&gt;"&gt; &lt;a class="btn btn-mini icon-play"&gt;&lt;/a&gt; &lt;a class="btn btn-mini icon-volume-up"&gt;&lt;/a&gt; &lt;a class="btn btn-mini icon-trash"&gt;&lt;/a&gt; &lt;/div&gt; &lt;/td&gt; &lt;td&gt;&lt;%= rating_for t, "sound" %&gt;&lt;/td&gt; &lt;td&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;% end %&gt; &lt;/table&gt; </code></pre> <p>When I click the play button and the track begins to play, I want to append the track time column with the current track time data so it looks like this: 4:34/00:10 Where the time on the left I have in the table already and I want to append the new data after the /.</p> <p>My javascript code for soundmanager looks like this:</p> <pre><code> whileplaying: function() { var track_time = $('#time').html(); var seconds = Math.round(this.position/1000); var r = seconds % 60; var m = Math.floor(seconds / 60); var duration = (m &lt; 10 ? '0' + m : m) + ":" + (r &lt; 10 ? '0' + r : r); $('#time').html('&lt;p&gt;' + duration + '&lt;/p&gt;'); </code></pre> <p>Problem is that this current code completely replaces the current track time value instead of appending it, and if I use</p> <pre><code>$('#time').append('&lt;p&gt;' + duration + '&lt;/p&gt;'); </code></pre> <p>or</p> <pre><code>$('#time').text('&lt;p&gt;' + duration + '&lt;/p&gt;'); </code></pre> <p>It writes a new value in addition to the existing value which eventually scrolls across the page instead of simply replacing the existing data with the new values in place.</p> <p>Any ideas on how to do this? I'm very new to development and been stuck on this for about 2 days now.</p> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload