[jQuery] Re: text of first sibling of a parent...How do I get it
Thanks Gustavo I put in a kludge for this just to move on with the project. But I will try your suggestion in the near future and let you know. jake On Wed, Jun 3, 2009 at 11:38 PM, Gustavo Salomé wrote: > Try this: > $("#knowndiv').parent('td').prev().prev().html(); > > Think thats gonna work out. > > 2009/6/3 jake dimano >> >> Mauricio and Ricardo, >> I applied all the suggestions, parent(), parents() and all the other >> functions, but still to no avail. The weird thing is that when I >> strip out all the styles, attributes and events from the elements and >> reduce the number of "tr"s to less than 10 but keep the structure >> intact, it works! >> At any rate, thanks to all. Too much effort has gone fruitless at >> this point. I will have to resort to a different solution altogether. >> jake >> >> On Wed, Jun 3, 2009 at 2:44 PM, Mauricio (Maujor) Samy Silva >> wrote: >> >> On Wed, Jun 3, 2009 at 11:20 AM, BigAB wrote: >> >> >> >> > have you tried >> >> > var myText = $('#knowndiv').parents('tr').find('td:first').text(); >> >> > alert(myText); >> >> >> >> > The TR is really the parent of the TDs, not the table. >> > >> > For information only. >> > I've used parents() not parent(). >> > parents() means ancestor and table is ancestor of TDs >> > >> > See: http://docs.jquery.com/Traversing >> > Maurício >> > - >> > >> > -Mensagem Original- >> > De: Ricardo >> > Para: jQuery (English) >> > Enviada em: quarta-feira, 3 de junho de 2009 15:15 >> > Assunto: [jQuery] Re: text of first sibling of a parent...How do I get >> > it >> > >> > There is no reason why you shouldn't get this working with one of the >> > examples provided. For the nesting issue, filter with :first: >> > >> > $('#knowndiv').parents('tr:first').children('td:first').text(); >> > >> > parents(xx:first) is similar to closest(xx), only the latter will also >> > try to match the element itself. >> > >> > On Jun 3, 1:01 pm, jake dimano wrote: >> >> Yes, that is the first thing I did, to no avail. I think all I am >> >> left with just trudging through this with pure javascript. >> >> jake >> >> >> >> On Wed, Jun 3, 2009 at 11:20 AM, BigAB wrote: >> >> >> >> > have you tried >> >> > var myText = $('#knowndiv').parents('tr').find('td:first').text(); >> >> > alert(myText); >> >> >> >> > The TR is really the parent of the TDs, not the table. >> >> >> >> > On Jun 3, 7:33 am, jake dimano wrote: >> >> >> Mauricio, your code basically works fine on a simple test page. But >> >> >> there is something about my set-up that makes the bit about >> > ... > > > > -- > Gustavo Salome Silva >
[jQuery] Re: text of first sibling of a parent...How do I get it
Try this: $("#knowndiv').parent('td').prev().prev().html(); Think thats gonna work out. 2009/6/3 jake dimano > > Mauricio and Ricardo, > I applied all the suggestions, parent(), parents() and all the other > functions, but still to no avail. The weird thing is that when I > strip out all the styles, attributes and events from the elements and > reduce the number of "tr"s to less than 10 but keep the structure > intact, it works! > At any rate, thanks to all. Too much effort has gone fruitless at > this point. I will have to resort to a different solution altogether. > jake > > On Wed, Jun 3, 2009 at 2:44 PM, Mauricio (Maujor) Samy Silva > wrote: > >> On Wed, Jun 3, 2009 at 11:20 AM, BigAB wrote: > >> > >> > have you tried > >> > var myText = $('#knowndiv').parents('tr').find('td:first').text(); > >> > alert(myText); > >> > >> > The TR is really the parent of the TDs, not the table. > > > > For information only. > > I've used parents() not parent(). > > parents() means ancestor and table is ancestor of TDs > > > > See: http://docs.jquery.com/Traversing > > Maurício > > ----------------------------------------- > > > > -Mensagem Original- > > De: Ricardo > > Para: jQuery (English) > > Enviada em: quarta-feira, 3 de junho de 2009 15:15 > > Assunto: [jQuery] Re: text of first sibling of a parent...How do I get it > > > > There is no reason why you shouldn't get this working with one of the > > examples provided. For the nesting issue, filter with :first: > > > > $('#knowndiv').parents('tr:first').children('td:first').text(); > > > > parents(xx:first) is similar to closest(xx), only the latter will also > > try to match the element itself. > > > > On Jun 3, 1:01 pm, jake dimano wrote: > >> Yes, that is the first thing I did, to no avail. I think all I am > >> left with just trudging through this with pure javascript. > >> jake > >> > >> On Wed, Jun 3, 2009 at 11:20 AM, BigAB wrote: > >> > >> > have you tried > >> > var myText = $('#knowndiv').parents('tr').find('td:first').text(); > >> > alert(myText); > >> > >> > The TR is really the parent of the TDs, not the table. > >> > >> > On Jun 3, 7:33 am, jake dimano wrote: > >> >> Mauricio, your code basically works fine on a simple test page. But > >> >> there is something about my set-up that makes the bit about > > ... > -- Gustavo Salome Silva
[jQuery] Re: text of first sibling of a parent...How do I get it
Mauricio and Ricardo, I applied all the suggestions, parent(), parents() and all the other functions, but still to no avail. The weird thing is that when I strip out all the styles, attributes and events from the elements and reduce the number of "tr"s to less than 10 but keep the structure intact, it works! At any rate, thanks to all. Too much effort has gone fruitless at this point. I will have to resort to a different solution altogether. jake On Wed, Jun 3, 2009 at 2:44 PM, Mauricio (Maujor) Samy Silva wrote: >> On Wed, Jun 3, 2009 at 11:20 AM, BigAB wrote: >> >> > have you tried >> > var myText = $('#knowndiv').parents('tr').find('td:first').text(); >> > alert(myText); >> >> > The TR is really the parent of the TDs, not the table. > > For information only. > I've used parents() not parent(). > parents() means ancestor and table is ancestor of TDs > > See: http://docs.jquery.com/Traversing > Maurício > - > > -----Mensagem Original- > De: Ricardo > Para: jQuery (English) > Enviada em: quarta-feira, 3 de junho de 2009 15:15 > Assunto: [jQuery] Re: text of first sibling of a parent...How do I get it > > There is no reason why you shouldn't get this working with one of the > examples provided. For the nesting issue, filter with :first: > > $('#knowndiv').parents('tr:first').children('td:first').text(); > > parents(xx:first) is similar to closest(xx), only the latter will also > try to match the element itself. > > On Jun 3, 1:01 pm, jake dimano wrote: >> Yes, that is the first thing I did, to no avail. I think all I am >> left with just trudging through this with pure javascript. >> jake >> >> On Wed, Jun 3, 2009 at 11:20 AM, BigAB wrote: >> >> > have you tried >> > var myText = $('#knowndiv').parents('tr').find('td:first').text(); >> > alert(myText); >> >> > The TR is really the parent of the TDs, not the table. >> >> > On Jun 3, 7:33 am, jake dimano wrote: >> >> Mauricio, your code basically works fine on a simple test page. But >> >> there is something about my set-up that makes the bit about > ...
[jQuery] Re: text of first sibling of a parent...How do I get it
> On Wed, Jun 3, 2009 at 11:20 AM, BigAB wrote: > > > have you tried > > var myText = $('#knowndiv').parents('tr').find('td:first').text(); > > alert(myText); > > > The TR is really the parent of the TDs, not the table. For information only. I've used parents() not parent(). parents() means ancestor and table is ancestor of TDs See: http://docs.jquery.com/Traversing Maurício - -Mensagem Original- De: Ricardo Para: jQuery (English) Enviada em: quarta-feira, 3 de junho de 2009 15:15 Assunto: [jQuery] Re: text of first sibling of a parent...How do I get it There is no reason why you shouldn't get this working with one of the examples provided. For the nesting issue, filter with :first: $('#knowndiv').parents('tr:first').children('td:first').text(); parents(xx:first) is similar to closest(xx), only the latter will also try to match the element itself. On Jun 3, 1:01 pm, jake dimano wrote: > Yes, that is the first thing I did, to no avail. I think all I am > left with just trudging through this with pure javascript. > jake > > On Wed, Jun 3, 2009 at 11:20 AM, BigAB wrote: > > > have you tried > > var myText = $('#knowndiv').parents('tr').find('td:first').text(); > > alert(myText); > > > The TR is really the parent of the TDs, not the table. > > > On Jun 3, 7:33 am, jake dimano wrote: > >> Mauricio, your code basically works fine on a simple test page. But > >> there is something about my set-up that makes the bit about ...
[jQuery] Re: text of first sibling of a parent...How do I get it
ensure that the script src of jquery is correct On Wed, Jun 3, 2009 at 8:15 PM, Ricardo wrote: > > There is no reason why you shouldn't get this working with one of the > examples provided. For the nesting issue, filter with :first: > > $('#knowndiv').parents('tr:first').children('td:first').text(); > > parents(xx:first) is similar to closest(xx), only the latter will also > try to match the element itself. > > On Jun 3, 1:01 pm, jake dimano wrote: > > Yes, that is the first thing I did, to no avail. I think all I am > > left with just trudging through this with pure javascript. > > jake > > > > On Wed, Jun 3, 2009 at 11:20 AM, BigAB wrote: > > > > > have you tried > > > var myText = $('#knowndiv').parents('tr').find('td:first').text(); > > > alert(myText); > > > > > The TR is really the parent of the TDs, not the table. > > > > > On Jun 3, 7:33 am, jake dimano wrote: > > >> Mauricio, your code basically works fine on a simple test page. But > > >> there is something about my set-up that makes the bit about > > >> ".parents('table')" fail. My page still has the same exact element > > >> structure with 2 differences; there are 52 "tr"s in the table; also, > > >> all the elements (tables, trs, tds, divs...what have you,) are all > > >> full of styles, attributes, and onclick events to a fairly large > > >> extent. > > > > >> Other variations and combination of jQuery functions fail as well in > > >> getting the parent of this div in my page. > > > > >> I guess I'll just keep on truckin'. > > >> jake > > > > >> On Tue, Jun 2, 2009 at 3:52 PM, Mauricio (Maujor) Samy Silva > > > > >> wrote: > > >> > var myText = > $('#knowndiv').parents('table').find('td:first').text(); > > >> > alert(myText); > > > > >> > Maurício > > > > >> > -Mensagem Original- > > >> > De: con-man-jake > > >> > Para: jQuery (English) > > >> > Enviada em: terça-feira, 2 de junho de 2009 16:38 > > >> > Assunto: [jQuery] text of first sibling of a parent...How do I get > it > > > > >> > Still a newbie. > > >> > I have this: > > > > >> > > > >> > > > > > >> > > > >> > text I want to get > > >> > > > > > >> > > > >> > > > > > >> > > > >> > > > >> > > > > > >> > > > >> > > > > > >> > If I have the div with id of "knowndiv" as an object (call it > "obj"), > > >> > How do I get the text inside the first ? >
[jQuery] Re: text of first sibling of a parent...How do I get it
There is no reason why you shouldn't get this working with one of the examples provided. For the nesting issue, filter with :first: $('#knowndiv').parents('tr:first').children('td:first').text(); parents(xx:first) is similar to closest(xx), only the latter will also try to match the element itself. On Jun 3, 1:01 pm, jake dimano wrote: > Yes, that is the first thing I did, to no avail. I think all I am > left with just trudging through this with pure javascript. > jake > > On Wed, Jun 3, 2009 at 11:20 AM, BigAB wrote: > > > have you tried > > var myText = $('#knowndiv').parents('tr').find('td:first').text(); > > alert(myText); > > > The TR is really the parent of the TDs, not the table. > > > On Jun 3, 7:33 am, jake dimano wrote: > >> Mauricio, your code basically works fine on a simple test page. But > >> there is something about my set-up that makes the bit about > >> ".parents('table')" fail. My page still has the same exact element > >> structure with 2 differences; there are 52 "tr"s in the table; also, > >> all the elements (tables, trs, tds, divs...what have you,) are all > >> full of styles, attributes, and onclick events to a fairly large > >> extent. > > >> Other variations and combination of jQuery functions fail as well in > >> getting the parent of this div in my page. > > >> I guess I'll just keep on truckin'. > >> jake > > >> On Tue, Jun 2, 2009 at 3:52 PM, Mauricio (Maujor) Samy Silva > > >> wrote: > >> > var myText = $('#knowndiv').parents('table').find('td:first').text(); > >> > alert(myText); > > >> > Maurício > > >> > -Mensagem Original- > >> > De: con-man-jake > >> > Para: jQuery (English) > >> > Enviada em: terça-feira, 2 de junho de 2009 16:38 > >> > Assunto: [jQuery] text of first sibling of a parent...How do I get it > > >> > Still a newbie. > >> > I have this: > > >> > > >> > > > >> > > >> > text I want to get > >> > > > >> > > >> > > > >> > > >> > > >> > > > >> > > >> > > > >> > If I have the div with id of "knowndiv" as an object (call it "obj"), > >> > How do I get the text inside the first ?
[jQuery] Re: text of first sibling of a parent...How do I get it
I must say, I have not tried "closest()" and "prevAll()". I'll give it another go with your suggestions before I throw in the towel. Thanks. jake On Wed, Jun 3, 2009 at 11:22 AM, mkmanning wrote: > > The problem with parents() in the example given is that if your page > structure is more complex, and has nested tables for example, then > parents() will return all parent tables. Likewise if there are tr's > preceding the tr in your example. Here's a couple ways to get the text > you're asking for: > > $('#knowndiv').closest('tr').find('td:first').text(); > > $('#knowndiv').parent().prevAll(':last').text(); > > HTH :) > > On Jun 3, 6:33 am, jake dimano wrote: >> Mauricio, your code basically works fine on a simple test page. But >> there is something about my set-up that makes the bit about >> ".parents('table')" fail. My page still has the same exact element >> structure with 2 differences; there are 52 "tr"s in the table; also, >> all the elements (tables, trs, tds, divs...what have you,) are all >> full of styles, attributes, and onclick events to a fairly large >> extent. >> >> Other variations and combination of jQuery functions fail as well in >> getting the parent of this div in my page. >> >> I guess I'll just keep on truckin'. >> jake >> >> On Tue, Jun 2, 2009 at 3:52 PM, Mauricio (Maujor) Samy Silva >> >> wrote: >> > var myText = $('#knowndiv').parents('table').find('td:first').text(); >> > alert(myText); >> >> > Maurício >> >> > -Mensagem Original- >> > De: con-man-jake >> > Para: jQuery (English) >> > Enviada em: terça-feira, 2 de junho de 2009 16:38 >> > Assunto: [jQuery] text of first sibling of a parent...How do I get it >> >> > Still a newbie. >> > I have this: >> >> > >> > >> >> > >> > text I want to get >> > >> >> > >> > >> >> > >> > >> > >> >> > >> > >> >> > If I have the div with id of "knowndiv" as an object (call it "obj"), >> > How do I get the text inside the first ? >
[jQuery] Re: text of first sibling of a parent...How do I get it
Yes, that is the first thing I did, to no avail. I think all I am left with just trudging through this with pure javascript. jake On Wed, Jun 3, 2009 at 11:20 AM, BigAB wrote: > > have you tried > var myText = $('#knowndiv').parents('tr').find('td:first').text(); > alert(myText); > > The TR is really the parent of the TDs, not the table. > > On Jun 3, 7:33 am, jake dimano wrote: >> Mauricio, your code basically works fine on a simple test page. But >> there is something about my set-up that makes the bit about >> ".parents('table')" fail. My page still has the same exact element >> structure with 2 differences; there are 52 "tr"s in the table; also, >> all the elements (tables, trs, tds, divs...what have you,) are all >> full of styles, attributes, and onclick events to a fairly large >> extent. >> >> Other variations and combination of jQuery functions fail as well in >> getting the parent of this div in my page. >> >> I guess I'll just keep on truckin'. >> jake >> >> On Tue, Jun 2, 2009 at 3:52 PM, Mauricio (Maujor) Samy Silva >> >> wrote: >> > var myText = $('#knowndiv').parents('table').find('td:first').text(); >> > alert(myText); >> >> > Maurício >> >> > -Mensagem Original- >> > De: con-man-jake >> > Para: jQuery (English) >> > Enviada em: terça-feira, 2 de junho de 2009 16:38 >> > Assunto: [jQuery] text of first sibling of a parent...How do I get it >> >> > Still a newbie. >> > I have this: >> >> > >> > >> >> > >> > text I want to get >> > >> >> > >> > >> >> > >> > >> > >> >> > >> > >> >> > If I have the div with id of "knowndiv" as an object (call it "obj"), >> > How do I get the text inside the first ? >
[jQuery] Re: text of first sibling of a parent...How do I get it
The problem with parents() in the example given is that if your page structure is more complex, and has nested tables for example, then parents() will return all parent tables. Likewise if there are tr's preceding the tr in your example. Here's a couple ways to get the text you're asking for: $('#knowndiv').closest('tr').find('td:first').text(); $('#knowndiv').parent().prevAll(':last').text(); HTH :) On Jun 3, 6:33 am, jake dimano wrote: > Mauricio, your code basically works fine on a simple test page. But > there is something about my set-up that makes the bit about > ".parents('table')" fail. My page still has the same exact element > structure with 2 differences; there are 52 "tr"s in the table; also, > all the elements (tables, trs, tds, divs...what have you,) are all > full of styles, attributes, and onclick events to a fairly large > extent. > > Other variations and combination of jQuery functions fail as well in > getting the parent of this div in my page. > > I guess I'll just keep on truckin'. > jake > > On Tue, Jun 2, 2009 at 3:52 PM, Mauricio (Maujor) Samy Silva > > wrote: > > var myText = $('#knowndiv').parents('table').find('td:first').text(); > > alert(myText); > > > Maurício > > > -Mensagem Original- > > De: con-man-jake > > Para: jQuery (English) > > Enviada em: terça-feira, 2 de junho de 2009 16:38 > > Assunto: [jQuery] text of first sibling of a parent...How do I get it > > > Still a newbie. > > I have this: > > > > > > > > > > text I want to get > > > > > > > > > > > > > > > > > > > > > > If I have the div with id of "knowndiv" as an object (call it "obj"), > > How do I get the text inside the first ?
[jQuery] Re: text of first sibling of a parent...How do I get it
have you tried var myText = $('#knowndiv').parents('tr').find('td:first').text(); alert(myText); The TR is really the parent of the TDs, not the table. On Jun 3, 7:33 am, jake dimano wrote: > Mauricio, your code basically works fine on a simple test page. But > there is something about my set-up that makes the bit about > ".parents('table')" fail. My page still has the same exact element > structure with 2 differences; there are 52 "tr"s in the table; also, > all the elements (tables, trs, tds, divs...what have you,) are all > full of styles, attributes, and onclick events to a fairly large > extent. > > Other variations and combination of jQuery functions fail as well in > getting the parent of this div in my page. > > I guess I'll just keep on truckin'. > jake > > On Tue, Jun 2, 2009 at 3:52 PM, Mauricio (Maujor) Samy Silva > > wrote: > > var myText = $('#knowndiv').parents('table').find('td:first').text(); > > alert(myText); > > > Maurício > > > -Mensagem Original- > > De: con-man-jake > > Para: jQuery (English) > > Enviada em: terça-feira, 2 de junho de 2009 16:38 > > Assunto: [jQuery] text of first sibling of a parent...How do I get it > > > Still a newbie. > > I have this: > > > > > > > > > > text I want to get > > > > > > > > > > > > > > > > > > > > > > If I have the div with id of "knowndiv" as an object (call it "obj"), > > How do I get the text inside the first ?
[jQuery] Re: text of first sibling of a parent...How do I get it
Mauricio, your code basically works fine on a simple test page. But there is something about my set-up that makes the bit about ".parents('table')" fail. My page still has the same exact element structure with 2 differences; there are 52 "tr"s in the table; also, all the elements (tables, trs, tds, divs...what have you,) are all full of styles, attributes, and onclick events to a fairly large extent. Other variations and combination of jQuery functions fail as well in getting the parent of this div in my page. I guess I'll just keep on truckin'. jake On Tue, Jun 2, 2009 at 3:52 PM, Mauricio (Maujor) Samy Silva wrote: > var myText = $('#knowndiv').parents('table').find('td:first').text(); > alert(myText); > > Maurício > > -Mensagem Original- > De: con-man-jake > Para: jQuery (English) > Enviada em: terça-feira, 2 de junho de 2009 16:38 > Assunto: [jQuery] text of first sibling of a parent...How do I get it > > Still a newbie. > I have this: > > > > > > text I want to get > > > > > > > > > > > > > If I have the div with id of "knowndiv" as an object (call it "obj"), > How do I get the text inside the first ?
[jQuery] Re: text of first sibling of a parent...How do I get it
var myText = $('#knowndiv').parents('table').find('td:first').text(); alert(myText); Maurício -Mensagem Original- De: con-man-jake Para: jQuery (English) Enviada em: terça-feira, 2 de junho de 2009 16:38 Assunto: [jQuery] text of first sibling of a parent...How do I get it Still a newbie. I have this: text I want to get If I have the div with id of "knowndiv" as an object (call it "obj"), How do I get the text inside the first ?
[jQuery] Re: text of first sibling of a parent...How do I get it
first lets give an ID to your table now heres your script. var obj = $("mytable"); var rows = $("tr"): // according to this we going to find text in the first td of the first tr rows.each(function(i) { var columns = rows.eq(i); alert(columns.eq(0).text()); }); the script above should give you some direction in navigating through a table and addressing specific columns in specific rows. but lets say you stuck with only that div having a id and can't do much then your script would be as follows var obj = $("#knowndiv"); var navigator = obj.parent(); // you have just set the navigator to be on the td that wraps the div navigator = navigator.parent(); // now you selected the td navigator = navigator.prev(); // you have now selected the previous tr navigator = $("td", navigator); // you have now selected the td tag in that tr // you can alert the text like so alert(navigator.text(); // however you may be faced with multiple td tags and you only want to alert the first one // in that case navigator = navigator.eq(0); // you have slected the very first td alert(navigato.text): On Tue, Jun 2, 2009 at 9:38 PM, con-man-jake < jakedim...@gmail.com> wrote: > > Still a newbie. > I have this: > > > > > > text I want to get > > > > > > > > > > > > > If I have the div with id of "knowndiv" as an object (call it "obj"), > How do I get the text inside the first ? >