title: How do I make a SignalR client something when it receives a message?
body: <p>I want to do something when a client receives a message via a SignalR hub.</p>
  
  <p>I've put together a basic chat app, but want people to be able to "like" a chat comment. I'm thinking the way to do this is to find the chat message on the client's page and update it using javascript. In the meantime to "prove the concept" I just want to make an alert popup on the client machine to say another user likes the comment.</p>
  
  <p>Trouble is, I'm not sure where to put it. (Am struggling to find SignalR documentation to be honest.) can't get my head round what is calling what here.</p>
  
  <p>My ChatHub class is as follows:</p>
  
  <pre><code>    public class ChatHub : Hub
      {
        public void Send(string name, string message)
        {
          // Call the broadcastMessage method to update clients.
          Clients.All.broadcastMessage(name, message);
        }
  
      }
  </code></pre>
  
  <p>And my JavaScript is:</p>
  
  <pre><code>        $(function () {
          // Declare a proxy to reference the hub. 
          var chat = $.connection.chatHub;
          // Create a function that the hub can call to broadcast messages.
          chat.client.broadcastMessage = function (name, message) {
              // Html encode display name and message. 
              var encodedName = $('&lt;div /&gt;').text(name).html();
              var encodedMsg = $('&lt;div /&gt;').text(message).html();
  
              // Add the message to the page. 
              var divContent = $('#discussion').html();
              $('#discussion').html('&lt;div class="container"&gt;' +
                                          '&lt;div class="content"&gt;' +
                                              '&lt;p class="username"&gt;' + encodedName + '&lt;/p&gt;' +
                                              '&lt;p class="message"&gt;' + encodedMsg + '&lt;/p&gt;' +
                                          '&lt;/div&gt;' +
                                          '&lt;div class="slideout"&gt;' +
                                              '&lt;div class="clickme" onclick="slideMenu(this)"&gt;&lt;/div&gt;' +
                                                 '&lt;div class="slidebutton"&gt;&lt;img id="imgid" onclick="likeButtonClick(this)" src="Images/like.png" /&gt;&lt;/div&gt;' +
                                                  '&lt;div class="slidebutton"&gt;&lt;img onclick="commentButtonClick(this)" src="Images/comment.png" /&gt;&lt;/div&gt;' +
                                                  '&lt;div class="slidebutton" style="margin-right:0px"&gt;&lt;img onclick="redcardButtonClick(this)" src="Images/redcard.png" /&gt;&lt;/div&gt;' +
                                           '&lt;/div&gt;' +
                                       '&lt;/div&gt;' + divContent);
  
          };
          // Set initial focus to message input box.  
          $('#message').focus();
          // Start the connection.
          $.connection.hub.start().done(function () {
             $('#sendmessage').click(function () {
                  // Call the Send method on the hub.                
                  chat.server.send($('#lblUser').html(), $('#message').val());
                  // Clear text box and reset focus for next comment. 
                  $('#message').val('').focus();
              });
          });      
  </code></pre>