Take the 2-minute tour ×

if i have this code in jquery:

var parentDiv = $(this).parent('.copyInstance');

inside this div there is a form.

how do i reference a form element inside this selector? i want something like this

  $.post($(parentDiv + " Form").attr('action'), $(parentDiv + " Form").serialize(),  function(data) {

but this above doesn't seem to work

share|improve this question
I don't understand the question. –  cletus May 13 '10 at 10:50
@cletus - i added in what i am trying to hopefully explain the issue better. let me know if this helps –  leora May 13 '10 at 10:53
Perhaps it would be better if you explained what you were trying to do and why. –  cletus May 13 '10 at 10:55
add comment

2 Answers

up vote 1 down vote accepted

To reference a children element you can use .find() for example:

    function(data) {

Depending on how it is structured you could also use .children() like:

share|improve this answer
parentDiv is already a jQuery object, no need to clone it :) –  Nick Craver May 13 '10 at 11:03
I stand corrected, I was thinking about the "this" which should be encapsulate in $() since it otherwise does not work in some IE versions... –  alexteg May 13 '10 at 15:29
add comment

You have 3 options for this selector:

parentDiv.find('form') //finds any form at any level deep inside
parentDiv.children('form') //finds forms that are immediate children
$("form", parentDiv) //really calls .find() but easier on the eyes maybe?

Here's more info on .find(), .children() and jQuery(selector, context).

share|improve this answer
add comment

Your Answer


