Guys, the codes work now !
Thanks a lot for the help !
Chris
Karl Swedberg-2 wrote:
>
> Are you sure? Maybe the problem is with "source.id"
>
> I put your HTML into a page and ran this code (on document ready):
>
> $('input').click(function() {
> var parentId = $(this).parents('div.parent')[0].id;
> alert(parentId);
> });
>
> When I clicked the first button, the alert read "parent1"
> When I clicked the second, the alert read "parent2"
>
> If that isn't what you're expecting, maybe I'm misunderstanding what
> you're trying to do.
>
>
> --Karl
> _________________
> Karl Swedberg
> www.englishrules.com
> www.learningjquery.com
>
>
>
> On Feb 15, 2007, at 12:02 PM, Mahadewa wrote:
>
>>
>> This doesn't do it for me. I got the Button itself as a result.
>>
>> var parent = $(this).parents('div.parent');
>>
>> Is this not the same as to say: "Select element (of 'this') which
>> parent is
>> 'div.parent' " ?
>>
>> I think I need the other-way around, don't I ?
>> Something like ... "Get me the element, which class is 'parent',
>> which has
>> 'this' children.
>>
>> Chris
>>
>>
>> Karl Swedberg-2 wrote:
>>>
>>> On Feb 15, 2007, at 11:01 AM, Mahadewa wrote:
>>>
>>>> // This function is wired to the above buttons' onclick event,
>>>> passing
>>>> 'this' as an argument
>>>> function OnButtonClick(source)
>>>> {
>>>> var parent = $(".parent").children(source.id);
>>>> }
>>>
>>> Hi Chris,
>>>
>>> you should be able to do it this way:
>>>
>>> var parent = $(this).parents('div.parent');
>>>
>>>
>>>
>>> --Karl
>>> _________________
>>> Karl Swedberg
>>> www.englishrules.com
>>> www.learningjquery.com
>>>
>>>
>>>
>>> On Feb 15, 2007, at 11:01 AM, Mahadewa wrote:
>>>
>>>>
>>>> Hi all,
>>>>
>>>> I've got the following problem ...
>>>>
>>>> Let's say I have the following html:
>>>>
>>>> <div class="parent" id="parent1">
>>>> <div class="sub">
>>>> <input id="parent1_Button" class="mybutton"
>>>> type="button"
>>>> value="button" />
>>>> </div>
>>>> </div>
>>>> <div class="parent" id="parent2">
>>>> <div class="sub">
>>>> <input id="parent2_Button" class="mybutton"
>>>> type="button"
>>>> value="button" />
>>>> </div>
>>>> </div>
>>>>
>>>> Now given a JQuery object of any of the button, how can I select
>>>> its parent
>>>> div (the one with the class "parent") ?
>>>>
>>>> I have tried the following, but it doesn't seem to yield the
>>>> correct object:
>>>>
>>>> // This function is wired to the above buttons' onclick event,
>>>> passing
>>>> 'this' as an argument
>>>> function OnButtonClick(source)
>>>> {
>>>> var parent = $(".parent").children(source.id);
>>>> }
>>>>
>>>> Thanks a lot !
>>>> Chris
>>>> --
>>>> View this message in context: http://www.nabble.com/Parent-
>>>> Selection-Problem-tf3234532.html#a8987992
>>>> Sent from the JQuery mailing list archive at Nabble.com.
>>>>
>>>>
>>>> _______________________________________________
>>>> jQuery mailing list
>>>> [email protected]
>>>> http://jquery.com/discuss/
>>>
>>>
>>> _______________________________________________
>>> jQuery mailing list
>>> [email protected]
>>> http://jquery.com/discuss/
>>>
>>>
>>
>> --
>> View this message in context: http://www.nabble.com/Parent-
>> Selection-Problem-tf3234532.html#a8989357
>> Sent from the JQuery mailing list archive at Nabble.com.
>>
>>
>> _______________________________________________
>> jQuery mailing list
>> [email protected]
>> http://jquery.com/discuss/
>
>
> _______________________________________________
> jQuery mailing list
> [email protected]
> http://jquery.com/discuss/
>
>
--
View this message in context:
http://www.nabble.com/Parent-Selection-Problem-tf3234532.html#a9001081
Sent from the JQuery mailing list archive at Nabble.com.
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/