What's the correct syntax for this jQuery selector?

  • mindfullsilence
  • Professor
  • Professor
  • User avatar
  • Posts: 854

Post 3+ Months Ago

I want to use "this" along with the child selector.

Something like this, but it's not working:

JAVASCRIPT Code: [ Select ]
$(this '> li').css("border","3px solid red");
 
  1. $(this '> li').css("border","3px solid red");
  2.  
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • UPSGuy
  • Lurker ಠ_ಠ
  • Web Master
  • User avatar
  • Posts: 2733
  • Loc: Nashville, TN

Post 3+ Months Ago

There's a few different options for you, but the easiest and most readable IMO is this:
Code: [ Select ]
$(this).find('li');


Other options could be:
Code: [ Select ]
$("li", this); //after researching, looks like this just does a find() anyways

-OR-

$(this).children("li");
  1. $("li", this); //after researching, looks like this just does a find() anyways
  2. -OR-
  3. $(this).children("li");
  • mindfullsilence
  • Professor
  • Professor
  • User avatar
  • Posts: 854

Post 3+ Months Ago

so it's not possible to traverse within the initial selector if starting with "this"?

JAVASCRIPT Code: [ Select ]
$(this '*');
 
$('*' this);
 
$(this.className);
 
$(this #idName);
 
  1. $(this '*');
  2.  
  3. $('*' this);
  4.  
  5. $(this.className);
  6.  
  7. $(this #idName);
  8.  
  • UPSGuy
  • Lurker ಠ_ಠ
  • Web Master
  • User avatar
  • Posts: 2733
  • Loc: Nashville, TN

Post 3+ Months Ago

Not that I've seen in use.

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 67 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.