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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:39:07+00:00 2026-06-05T10:39:07+00:00

I have a span tag that looks like the following: <span class=myClass>Lorem ipsum</span> I

  • 0

I have a span tag that looks like the following:

<span class="myClass">Lorem ipsum</span>

I would like to add an attribute to it that references the innerText value (for a javascript function call), and I would like it to look like this:

<span class="myClass" data-bind="click: function(data, event) { myFunction('Lorem ipsum') }">Lorem ipsum</span>

I want to be able to dynamically parse a paragraph of text that contains spans of span myClass, and add the attribute programmatically. As such, if my innerText was “Sed”, the argument to myFunction would be “Sed”.

I tried the following to produce this:

jquery(container).find('.myClass').attr('data-bind', 'click: function(data, event) { myFunction(' + $(this).text() + ')}');

It didn’t work. (The function argument was empty. Trying .html() outputs “null”.)

Does anyone know how to accomplish something like this in jQuery? I believe that my issue is the $(this) keyword, as it’s not pointing to the object in question. I’m not sure if there’s another keyword that I can use…

Thank you!

Edit: Whoops, I attempted to obfuscate my code a little, and forgot to do it for the last line. Sorry for any confusion.

  • 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-06-05T10:39:08+00:00Added an answer on June 5, 2026 at 10:39 am

    Your code doesn’t work because $(this) isn’t your element.

    try:

    jquery(container).find('.nonGlossaryKeyword').each(function(){
       $(this).attr('data-bind', 'click: function(data, event) { showNonGlossaryModal(' + $(this).text() + ')}');
    });
    

    in this case, $(this) iterates over all the .nonGlassorayKeyword elements, like a for loop.

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

Sidebar

Related Questions

I have code that looks like this: <div id="header"> <ul class="tabs"> <li><a href="/user/view"><span class="tab">Profile</span></a></li>
i have the following text: <span term=db6ff2ffe2df7b8cfc0d9542bdce27dc class=yellowback>Lorem</span> <span term=e78f5438b48b39bcbdea61b73679449d class=yellowback>ipsum</span> dolor sit amet,
I have two span elements that I would like to stay on the same
I have html that looks like this, <div> <span>Text <a href=example.html>ABC</a> <a href=example.html>DEF</a> <a
I have some HTML as such: <span class=number>1.</span>Lorem ipsum dolor. <span class=special>Sit amet.</span> Consectur
I have a page that looks something like this: ... <div class=container> <div class=info>
I have a span that is generated through javascript, with its css class as
I have an input box and I have a span tag that contains some
So i have a pre tag like so: <pre> Some content, more content. <span>Coloured
Say I have HTML that looks like this: <p> May 4 - <a href=http://auburn.craigslist.org/web/2996976345.html>residual

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.