jQuery
Add chat to your jQuery site
Put a TalkJS chatbox in your page template so visitors can message each other. For example, a “Message the seller” button can open the right conversation from a jQuery click handler. TalkJS supplies the chat UI and keeps the conversation history.
// Open the seller's conversation on click
$('.message-seller').on('click', function () {
$('#chat').attr('conversation-id', $(this).data('conversation-id'));
});
// jQuery wraps the event: the message is on originalEvent
$('#chat').on('send-message', function (e) {
console.log(e.originalEvent.message);
});


Why e.message is undefined in your jQuery handler
The <t-chatbox> docs read a sent message from event.message. Listen the jQuery way, with .on(), and the same property comes back undefined:
$('#chat').on('send-message', function (e) {
console.log(e.message); // undefined
console.log(e.originalEvent.message); // the message that was sent
});jQuery doesn’t pass your handler the browser’s event. It wraps it in its own event object, which carries a set list of properties, and message isn’t on that list. jQuery’s event object docs say where the rest went: “To access event properties not listed above, use the event.originalEvent object.” We tested this with jQuery 4.1.0.
That’s jQuery’s rule, not a TalkJS quirk, so it holds for every property jQuery doesn’t list. If you’d rather skip the wrapper, a plain addEventListener on the element gets event.message directly, as the docs show.
Open a conversation from a jQuery click
You don’t need jQuery to create the chat. Write the <t-chatbox> tag into the template your server already renders, and load it with the three tags from the Components SDK install docs in your <head>:
<!-- In the <head> -->
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@talkjs/web-components@0.3.14/default.css"
/>
<script type="importmap">
{
"imports": {
"@talkjs/web-components": "https://cdn.jsdelivr.net/npm/@talkjs/web-components@0.3.14",
"@talkjs/core": "https://cdn.jsdelivr.net/npm/@talkjs/core@1.12.1"
}
}
</script>
<script type="module" async>
import "@talkjs/web-components";
</script>
<!-- Where the chat goes -->
<t-chatbox
id="chat"
style="display: block; width: 420px; height: 500px;"
app-id="<APP_ID>"
user-id="sample_user_alice"
conversation-id="sample_conversation"
></t-chatbox>Replace <APP_ID> with your test mode app ID, from the Settings page of your TalkJS dashboard. Test mode comes with sample users and a sample conversation, so the chat opens on sample_user_alice’s conversation.
Then let jQuery open a conversation when someone clicks. Put the conversation ID on the link, and set it on the chatbox with .attr():
<a href="#" class="message-seller" data-conversation-id="order_1042">Message the seller</a>
<script>
$('.message-seller').on('click', function (e) {
e.preventDefault();
$('#chat').attr('conversation-id', $(this).data('conversation-id'));
});
</script>Change conversation-id and the chat switches to that conversation at once, with no page reload.

conversation-id to order_1042, November 2026.The chat only opens a conversation that already exists. Point it at an ID TalkJS doesn’t know, and it shows “Conversation not found”. So create the conversation first, for example when the order is placed, with a PUT to the REST API. List the participants, including the user who will click the link:
PUT /v1/<APP_ID>/conversations/order_1042
{
"participants": ["sample_user_alice", "<SELLER_ID>"],
"subject": "Order 1042"
}The REST API needs your secret key, so this call runs on your server, never in the page. If your server runs PHP, PHP chat with TalkJS shows how to make that call.
Before you go live, turn on authentication. It’s off when you create your account, and until you turn it on, anyone can open the chat as any user-id. With it on, your server signs a token for each user.
Still on the Classic SDK’s copy-and-paste snippet? Its mount() takes a jQuery object as it is: chatbox.mount($('#talkjs-container')) mounts the chat into the first element that matches. For new projects, use the Components SDK above.
We were able to offload all messaging to TalkJS — hugely simplifying our development of an otherwise complex stack.
Ready-made chat UI you can customize
On the Components SDK, the chat UI comes in three layouts that you can mix and match: an inbox, a chatbox for one conversation, and a conversation list.
The TalkJS Inbox shows the chat history on the left, selected conversation on the right. It's designed to act as the messaging center of your app, usually living on its own page.
The TalkJS Chatbox is the right half of the Inbox UI mode. It takes up less space and is designed to be embedded in your app near an order confirmation, a booking, or user profile.
A list of the user’s conversations. Pair it with a Chatbox to open the selected one, or use the Inbox, which has both.