I'm trying to clean up my code, and I find in my script many snippets that are similar to the following:
$msg.html('<a href="#" data-userName=' + msg.user +
' class="userName" onClick="showCurrUsersMsgs(this);">@' + msg.user + '</a>' + '<span class="timestamp"> <b>·</b> ' +
jQuery.timeago(msg.created_at) +'</span></br>' +
msg.message);
I tried doing something like
var $userProfile = $('<a href="#" data-userName=' + msg.user +
' class="userName" onClick="showCurrUsersMsgs(this);">@' + msg.user + '</a>');
var $timeStamp = $('<span class="timestamp"> <b>·</b> ' +
jQuery.timeago(msg.created_at) +'</span>');
$msg.html($userProfile + $timeStamp + '</br>' + msg.message);
to make it more readable, but then the page doesn't build correctly. Instead, it shows something like [Object][Object]
.
Why is this happening, and how do I fix this error?