What's the correct syntax for this jQuery selector?

  • mindfullsilence
  • Professor
  • Professor
  • User avatar
  • Joined: Aug 04, 2008
  • Posts: 846
  • Status: Offline

Post January 14th, 2010, 9:18 pm

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.  
Use your words like arrows to shoot toward your goal.
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post January 14th, 2010, 9:18 pm

  • UPSGuy
  • Lurker ಠ_ಠ
  • Web Master
  • User avatar
  • Joined: Jul 25, 2005
  • Posts: 2735
  • Loc: Nashville, TN
  • Status: Offline

Post January 14th, 2010, 11:25 pm

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");
I'd love to change the world, but they won't give me the source code.
  • mindfullsilence
  • Professor
  • Professor
  • User avatar
  • Joined: Aug 04, 2008
  • Posts: 846
  • Status: Offline

Post January 15th, 2010, 10:31 am

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.  
Use your words like arrows to shoot toward your goal.
  • UPSGuy
  • Lurker ಠ_ಠ
  • Web Master
  • User avatar
  • Joined: Jul 25, 2005
  • Posts: 2735
  • Loc: Nashville, TN
  • Status: Offline

Post January 15th, 2010, 1:44 pm

Not that I've seen in use.
I'd love to change the world, but they won't give me the source code.

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 125 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
 
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.