[jQuery] Re: Shortest Selector

2007-05-22 Thread Jean Nascimento


i want to lnow too, and including a question
How can I remove the TR who includes the finded element?

On 5/22/07, Glen Lipka [EMAIL PROTECTED] wrote:

TR
  TD
 AONE/A
  /TD
/TR
TR
   TD
  DIVTWO/DIV
   /TD
 /TR


What is the shortest Selector to find the DIV if one starts with A (this)

This is the best I got, but is there a shorter way?
$(this).parents(tr).next(tr).find(div)


Glen



--

[]´s Jean
www.suissa.info

  Ethereal Agency
www.etherealagency.com


[jQuery] Re: Shortest Selector

2007-05-22 Thread Sean Catchpole

I believe that might be the shortest way to get the element, however if
speed is your concern, then I suggest storing the divs before hand. Give
this code a try:

var div = $(tr td div);
$(tr td a).each(function(i){
 $(this).click(function(){
   alert(div[i].innerHTML);
   return false;
 });
});

~Sean


[jQuery] Re: Shortest Selector

2007-05-22 Thread Glen Lipka

But your answer is much longer than
$(this).parents(tr).next(tr).find(div)

I'm not saying I want to bind the click or get the value of the DIV.  I just
want to find it with a single selector.
Actually I plan to slideDown() the Div using Toggle on the A.

Glen

On 5/22/07, Sean Catchpole [EMAIL PROTECTED] wrote:


I believe that might be the shortest way to get the element, however if
speed is your concern, then I suggest storing the divs before hand. Give
this code a try:

var div = $(tr td div);
$(tr td a).each(function(i){
  $(this).click(function(){
alert(div[i].innerHTML);
return false;
  });
});

~Sean


[jQuery] Re: Shortest Selector

2007-05-22 Thread Daemach

It depends on how much control you have over the original HTML.  If
you're generating it from a dynamic language like coldFusion, ASP,
PHP, etc. and you will always be linking a specific link with a
specific div AND you don't mind adding ID's the fastest selector is $
('#'+this.id.split(_)[1]);  You could go shorter by using a class -
it would be $('div.c1'); but the lookup is faster with ID's if only by
a few ms.

Otherwise, yours looks as short as safely possible.  While you can
pass an expression to parent(), I doubt $(this).parents(tr + tr
div); would work, though I think it would as a straight css selector.

TR
  TD
 A id=a_1 class=c1ONE/A
  /TD
/TR
TR
  TD
 DIV id=div_1 class=c1TWO/DIV
  /TD
/TR

FWIW :)
On May 22, 4:52 pm, Glen Lipka [EMAIL PROTECTED] wrote:
 But your answer is much longer than
 $(this).parents(tr).next(tr).find(div)

 I'm not saying I want to bind the click or get the value of the DIV.  I just
 want to find it with a single selector.
 Actually I plan to slideDown() the Div using Toggle on the A.

 Glen

 On 5/22/07, Sean Catchpole [EMAIL PROTECTED] wrote:



  I believe that might be the shortest way to get the element, however if
  speed is your concern, then I suggest storing the divs before hand. Give
  this code a try:

  var div = $(tr td div);
  $(tr td a).each(function(i){
$(this).click(function(){
  alert(div[i].innerHTML);
  return false;
});
  });

  ~Sean