• Sign in to Neowin Faster!

    Create an account on Neowin to contribute and support the site.

  • 0
Sign in to follow this  

[jQuery] .find with multiple results.

Question

Axel    95
var colspanstart = $(rowID).find("td[colspan]").attr("class");

 

The above works but it only lets me manage the first element it finds matching that criteria on the row.

 

If there are multiple colspans on that row, how would I select the second or third one for example?

 

Many thanks.

Share this post


Link to post
Share on other sites

3 answers to this question

Recommended Posts

  • 0
mollick2    19

Your gonna want to use the each function

var colspanstart = new Array()
$(rowID).find("td[colspan]").each( function() {
    colspanstart.push( this.attr("class") )
})
  • Like 2

Share this post


Link to post
Share on other sites
  • 0
Axel    95

Brilliant! Many thanks.

Share this post


Link to post
Share on other sites
  • 0
spacer    988

I prefer to use "rowID" as a selector constraint.

 

$('td[colspan]', rowID)

 

Then you can use the ":eq()" filter in your selector if you really only want the second or third td.

 

$('td[colspan]:eq(2)', rowId)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.