javascriptjqueryruby-on-railsajaxajax-polling

simple ajax/jquery - trying to replace number


I am trying to replace content inside a span class with jquery. I know my jquery file is being read because the first line works. Essentially, the first line of jquery adds a new notification to a list of notifications. The second line of query should replace the existing number on the site with the new @unseen_notifications.count. The second line of the jquery file is not working. How do I fix it?

jquery:

$('#user_notifications').prepend("<%= j render(@user_notifications) %>");
$('#red-count').html.replaceWith("<%= @unseen_notifications.count %>");

html:

<span class="red-count">
    <%= @unseen_notifications.count %>
</span>

Solution

  • You cannot write html.replaceWith. Set the html like below

    $('.red-count').html("<%= @unseen_notifications.count %>");
    

    Also, red-count is a class, so use . instead of #