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 416255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T18:27:44+00:00 2026-05-12T18:27:44+00:00

I’ve written a plugin to highlight terms used to find a page . The

  • 0

I’ve written a plugin to highlight terms used to find a page. The source is also available.

My problem is, if you look at the first link’s inline JavaScript, I’ve made a custom textPlacement function to handle the insertion of the display bar (it looks a bit like Stack Overflow’s).

As you can see, I have an event handler on the button that is inserted. I have coded the removal of the bar, but I’d also like to remove the highlighting of the terms. The plugin has a method for doing this called toggleTermHighlighting().

How can I call that method from inside the anonymous function on the example page? Would I need to make it this.toggleTermHighlighting = function() {}. I’ve tried passing in an instance of this to the first argument, but could not get it to work.

Sorry, I always seem to have a tough time with scope in JavaScript.

Does anyone know what I could do to be able to access that method from inside the anonymous function from the example page?

  • 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-12T18:27:44+00:00Added an answer on May 12, 2026 at 6:27 pm

    I think if you restructured the way the function was defined inside the plugin, it would become quite a bit easier.

    Change line 128 from:

    var toggleTermHighlighting = function() {
    

    to:

    this.toggleTermHighlighting = function() {
    

    Then you can do something like this to access the function from a totally different scope:

    var myPlug = new $.fn.searchTermsHighlight();
    myPlug.toggleTermHighlighting();
    

    This would be an answer to your question, but I think a different approach might be more appropriate. If you look at a lot of the jQuery UI code, you can pass a string into the plugin and it will execute a function for you. So you could actually just do something like:

    $('body').searchTermsHighlight('toggle');
    

    and then just check for it at the top of your function, or in an init() type function

    if (options === 'toggle'){ toggleTermHighlighting(); return this; }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.