jQuery selector takes a second argument that sets context.

I was trying to concatenate a select to the almighty

this

in jQuery, but it just wasn't working.

I tried

$(this + 'input')

Didn't work, so I thought, maybe I need a space between this and input like so:
$(this + ' input')

No go..

Then I ran across this page.
http://stackoverflow.com/questions/306583/jquery-this-selector-and-children

Of course StackOverFlow has the answer.

The working result

$('input', this)

Perfect!!!

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <drupal5>, <drupal6>, <javascript>, <php>, <sql>. Beside the tag style "<foo>" it is also possible to use "[foo]".

More information about formatting options