0

I have a complex jquery expression which I have stored in the variable "that":

that = $('table[class=a]').find('a[href^="xx"]').closest('td')[0]


<td>
    <a href="xx....">
</td>

I'm not sure how to open the contained link using "that" as the starting point. I tried

 $(that>'a').each(function(){
            window.location.href = $(this).attr('href');
       });

this yields an empty set in firebug. How can I fix this?

2
  • Why don't you just stop here: $('table[class=a]').find('a[href^="xx"]') Commented Jan 2, 2014 at 3:34
  • 1
    I think it should be as simple as that = $('table[class=a]').find('a[href^="xx"]'); window.location = that.prop('href') Commented Jan 2, 2014 at 3:36

1 Answer 1

2

Instead of trying to find the first enclosing <td>, you can simply shorten the expression to get only the anchors:

$('table.a a[href^="xx"]').each(function() {
    location.href = this.href;
    return false;
});

This will take the first anchor, and if it exists, change the location.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.