Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3691756
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:11:01+00:00 2026-05-19T04:11:01+00:00

I have an HTML document with about 30,000 words in it. I’d like to

  • 0

I have an HTML document with about 30,000 words in it.

I’d like to be able to do something when a user clicks any word. For simplicity/concept right now, I’d just like to alert() that word.

For example, in the paragraph about, if I were to click on “have” it should run alert("have").

I’m using jQuery.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T04:11:01+00:00Added an answer on May 19, 2026 at 4:11 am
    var p = $('p');
    
    p
     .html(function(index, oldHtml) {
        return oldHtml.replace(/\b(\w+?)\b/g, '<span class="word">$1</span>')
     })
     .click(function(event) { alert(event.target.innerHTML) });
    

    I took Pablo Fernandez‘s suggestions into account.

    See it on jsFiddle.

    Update

    So, will this be performant (e.g., it won’t freeze up a slow user’s browser?) Also, could you elaborate about how event.target works?

    It may very well slow the performance of a page with 30,000 words. I’d argue that is excessive and probably would benefit from being paginated, but I don’t know your exact circumstances.

    event.target property holds the element that started the event – the event bubbles up / propagates to its parent, which then handles the event, so you don’t have 30,000 events on separate span elements.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an <img> in an HTML document that I would like to highlight
I'm not asking about converting a LaTeX document to html. What I'd like to
I have an HTML document that is using to embed a control. In some
I have an HTML (not XHTML) document that renders fine in Firefox 3 and
I am constructing a large HTML document from fragments supplied by users that have
I have html code that looks roughly like this: <div id=id1> <div id=id2> <p>some
I have HTML code like this : <div> <a>Link A1</a> <a>Link A2</a> <a>Link A3</a>
I have HTML code edited by FCKEditor stored in a database and would like
I have a string representing a stand-alone (and valid XHTML 1.0 Strict) HTML document,
I have an html document that I saved as a .txt file. I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.