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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:13:19+00:00 2026-05-22T03:13:19+00:00

I’m having some issues with attaching live event handlers to particular rows. What I

  • 0

I’m having some issues with attaching live event handlers to particular rows.


What I have and what I’m after:

I have some HTML that will be generated dynamically after page load as follows:

<table>
   <tr>
      <td></td>
   </tr>
   <tr>
      <td class="bonus"></td>
   </tr>
   <tr>
      <td></td>
   </tr>
 </table>

I would like to have two click events:

  1. One for rows that aren’t a “bonus row”
  2. One for rows that have a “bonus row” after them

What I’ve tried and the problem:

However, I cannot work out how to use a selector to select “element that has a particular element after it” (i.e. a “previous” selector). As such, the best I can arrive at is:

  1. Rows that aren’t a “bonus row”: $('tr:not(:has(.bonus))')
  2. Rows that have a “bonus row” after them: $('tr + tr:has(.bonus)').prev()

This is all well and good, except whenever I use the live() method on a jQuery object that was obtained through traversal, rather than pure selection i.e.

$('tr:has(.bonus)').prev().live('click', function() {
   alert('hello');
});

I get this error:

uncaught exception: Syntax error,
unrecognized expression: )


The issue as an even more minimal example:

I was hoping this was localised to some script I am using, but I’ve isolated this to a minimal jsFiddle example which still replicates the issue for me: http://jsfiddle.net/ptvrA/

HTML:

<div></div>
<div id="target"></div>

JS:

$('#target').prev().live('click', function () {
   alert('f');
});

It seems from this answer that this is a known limitation of live.


My workarounds

For reference, my workarounds are either:

  1. Mark the rows that have a “bonus row” after them in some way
  2. Bind the click to all rows, and do a check to see if there is a “bonus row” after them within the handler.

But if I can get a “nicer” solution, even out of curiosity in case I run into this problem in a different situation, I’d appreciate it.

Cheers

  • 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-22T03:13:20+00:00Added an answer on May 22, 2026 at 3:13 am

    To be honest, I’d just use your second idea and bind click to all rows, then check to see if next row has a bonus td in it, like this:

    $('tr:not(:has(.bonus))').live('click', function () {
        if ($(this).next().children('td').hasClass('bonus')) {
           alert('next row has bonus td');
        }
        else {
           alert('next row does not have bonus td');
        }
    });
    

    fiddle located here: http://jsfiddle.net/7gdqc/2/

    I don’t think there’s a pure selector way to do it, and this isn’t really a workaround – I’d call it a valid solution to your problem.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
We're building an app, our first using Rails 3, and we're having to build
I have a bunch of posts stored in text files formatted in yaml/textile (from

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.