For AI agents: Find a documentation index at https://talkjs.com/llms.txt (full content at https://talkjs.com/llms-full.txt). Get a markdown version of any page by appending .md to its URL path.
Skip to content

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);
});
Dev A
Hey, I'm trying to lift state up from a child component, but I'm getting undefined errors. Any ideas?
8m ago
You
Are you passing the state and the setState function correctly as props?
6m ago
Dev A
I think so, yes.
5m ago
ok-hand
thinking
You
Maybe you're not binding the handler in the constructor. That might be the issue.
2m ago
Dev A
typing...
just now
Write a reply...
You
Hey, I’m having trouble accessing my account. It says my password is incorrect.
5m ago
SupportBot
Hi there! No problem — let’s get that sorted. Have you tried resetting your password using the 'Forgot password?' link?
4m ago
thinking
thumbs-up
You
Yes, but I haven’t received the reset email yet.
3m ago
SupportBot
Thanks for confirming. I’ve just sent a new reset link to your email. Please check your inbox and spam folder.
2m ago
SupportBot
Is there anything else I can help you with?
just now
Got it — checking my inbox now!

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.

A TalkJS chatbox titled Order 1042 with Sebastian, showing his message: Hi Alice, your order shipped this morning. Tracking is in your email.
Alice’s chat right after she clicks “Message the seller” on a jQuery 4.1.0 page. The click set 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.

Classtime
Decathlon
Riot Games
Hyundai
Retreat Guru logo
We were able to offload all messaging to TalkJS — hugely simplifying our development of an otherwise complex stack.
Deryk Wenaus
CTO, Retreat Guru

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.

Inbox

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.

Chatbox

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.

Conversation list

A list of the user’s conversations. Pair it with a Chatbox to open the selected one, or use the Inbox, which has both.

FAQs

Yes, and it’s still maintained. Version 4.1.0 came out on November 17, 2026, ten months after 4.0.0.

No. A jQuery chat widget only draws the chat box. The messages need a server that stores them and delivers them to the other person, and if you build that yourself, notifications, moderation and message history are yours to build too. With TalkJS, that backend is ours: we keep message history with no time limit, moderation is built in, and email, SMS and push notifications come on every plan. SMS messages are charged separately.

No, but you can change how it looks. With the script tags you get a pre-built theme, and you can edit its CSS. To change how the components behave, install them with a package manager such as npm.

No. Every plan includes a free development mode, so you build and test first and pay when you go live. We charge per monthly active user: Basic is $279 a month, or $239 a month billed annually, with 10,000 monthly active users included. See pricing for the other plans.