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

  • SEARCH
  • Home
  • 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 8471505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:48:51+00:00 2026-06-10T16:48:51+00:00

I have been onto this for days and i seem not to be able

  • 0

I have been onto this for days and i seem not to be able to break even. I have a table that deplays a series of links in one of its cell – the last cell that is.
Now when clicked ,the text value in the last link changes(implemented with jsf ajax), to reflect the status of the row it resides in ,from ‘suspend’ to ‘resume’ and vice versa. i have used jQuery to change the background
color of a row whenever the document is loaded and the text link reads ‘resume’. See below on how i have implemented this

var defaultval;

$(" table tbody tr td:nth-child(7)").each(function() {
    defaultval = $(this).find("a:nth-child(4)").html();
    if (defaultval == "resume") {
        $(this).parents("tr").addClass("suspended")
    }

});​

Now i want this row background color to change whenever the link is clicked and its text value changes to ‘resume’ ,so i wrote JQuery code below

$("table tbody tr td:nth-child(7) ").click(function() {
    if ($(this).find("a:nth-child(4)").html() !== "resume") {
        $(this).parents("tr").addClass("suspended");
    }
    else {
        $(this).parents("tr").removeClass("suspended");
    }
});​ 

It seemed to work when i click on the link. But the problem is that when the cell itself and other links within the cell
are clicked it changes without the the text of the link changing because of the implementation above.
And when i do this:

$("table tbody tr td:nth-child(7) a:nth-child(4)").click(function() {
    if ($(this).html() !== "resume") {
        $(this).parents("tr").addClass("suspended");
    }else {
        $(this).parents("tr").removeClass("suspended");
    }
});​

It changes once and does not change back with further clicks.
Now i want to restrict this effect to only when this link is clicked.Thanks in anticipation of your Response(s).

  • 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-10T16:48:52+00:00Added an answer on June 10, 2026 at 4:48 pm

    By the sounds of it your code that changes the text in the link is actually fully replacing the link (a tag and all)… which means you remove the click event listener you’ve added. You have two options:

    Option one

    Don’t replace the link entirely, just change the text and it’s href (if needed). If you don’t remove / replace the original a tag, the click listener will remain in place and will trap more clicks after the first one. The following will allow you to just change the parts of the a that you need.

    $('table tbody tr td:nth-child(7) a:nth-child(4)')
        .attr('href', 'http://stackoverflow.com')
        .html('My new link text goes here');
    

    Option two

    Change your event listener to use .live or .on (depending on which version of jQuery you are using).

    $("table tbody tr td:nth-child(7) a:nth-child(4)").live('click', function() {
      if ($(this).html() !== "resume") {
        $(this).parents("tr").addClass("suspended");
      }else {
        $(this).parents("tr").removeClass("suspended");
      }
    });​
    

    What the above does is not actually bind the listener to the element, it binds it to the document instead, and when a click event is triggered on the document it bubbles the event up until the jQuery selector matches an element that received a click. This means you can modify the a link as much as you want… you could even add more a tags… and they would still all work as long as they matched the jQuery selector you used.

    further notes

    As an additional recommendation there are two things that I would alter about what you are doing.

    First, rather than using :nth-child() to target your elements, I would add classes to them and target them that way. This is much more future-proof if your table ever changes cell or row dimensions.

    Secondly, when refering to $(this) in your JavaScript it is far better to do the following:

    $("table tbody tr td.target-cell a.target-link").live('click', function() {
      var self = $(this);
      if (self.html() !== "resume") {
        self.parents("tr").addClass("suspended");
      }else {
        self.parents("tr").removeClass("suspended");
      }
    });​
    

    By creating a variable to store $(this) you optmise your code quite a lot, rather than having jQuery calculate $(this) every time.

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

Sidebar

Related Questions

I have been told that this is a useful means of checking code but
I have been struggling for days to get a working upload onto the admin
I have xml files been imported onto an FTP server. This is stored in
I am really sorry to ask this silly question. I have been onto this
Have been trying to encrypt an xml file to a string so that I
Have been working on this question for a couple hours and have come close
Here is my problem: I have just been brought onto a massive asp.net C#
I have been implementing AES onto my website for security and I have ran
I have been searching for a reason for this behavior in my code for
I have this question for my programming class which I have been struggling to

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.