Re: [jQuery] Parent and Single Parent Element Selection

2007-03-05 Thread Choan C. Gálvez
On 3/5/07, Kevin Fricovsky [EMAIL PROTECTED] wrote:

 Morning,

Evening ;)

 I have a question for the jquery group.

 My question is - what's the best way to get a single parent element of
 the current object.

 Right now I have an html table with multiple rows. In the first TD of
 each row I have a select list (a dropdown).

 I have a select() event attached to the option list and when the user
 selects an option the background color for that row (TR) is changed.
 (well, actually all TR backgrounds are changing right now that's why I'm
 writing everyone).

 So, the only problem I'm having is getting the single parent TR.

 Right now my update statement is updating every TR in the table versus
 just the parent.

 The code is something like this:

 $(../../../../tr,this).addClass(assigned);

 The this is the select element.

 Even if I do use an indexer on this statement like this $(...)[0] - the
 problem there is the system currently doesn't know the index of the row
 it's on.

 So I can either add the index in a hidden value or I thought maybe
 there's an easier way of doing this via JQuery.

There is.

$(this).parent(tr).addClass(assigned);



-- 
Choan
http://choangalvez.nom.es/

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Parent and Single Parent Element Selection

2007-03-05 Thread Seb Duggan
Maybe something like:


$('.colorPick').change(function() {
$(this).parent().parent().addClass('assigned');
});


where colorPick is the class assigned to your select menu.

You could also use:


$('.colorPick').change(function() {
$(this).parents('tr').addClass('assigned');
});


but my gut tells me that's not quite as efficient, as it will look  
for 'tr' elements all the way up to the top of the DOM tree.


Seb



On 5 Mar 2007, at 17:09, Kevin Fricovsky wrote:


 Morning,

 I have a question for the jquery group.

 My question is - what's the best way to get a single parent element of
 the current object.

 Right now I have an html table with multiple rows. In the first TD of
 each row I have a select list (a dropdown).

 I have a select() event attached to the option list and when the user
 selects an option the background color for that row (TR) is changed.
 (well, actually all TR backgrounds are changing right now that's  
 why I'm
 writing everyone).

 So, the only problem I'm having is getting the single parent TR.

 Right now my update statement is updating every TR in the table versus
 just the parent.

 The code is something like this:

 $(../../../../tr,this).addClass(assigned);

 The this is the select element.

 Even if I do use an indexer on this statement like this $(...)[0] -  
 the
 problem there is the system currently doesn't know the index of the  
 row
 it's on.

 So I can either add the index in a hidden value or I thought maybe
 there's an easier way of doing this via JQuery.

 Thx for your help.


 ___
 jQuery mailing list
 discuss@jquery.com
 http://jquery.com/discuss/



___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/