2

I am using jQuery selector in an AJAX request call , so according to the value returned by request , I select the required div using :eq() selector, but the problem is that I am stuck with some undefined stuffs

Here is what I wish to do

$('.win7red:eq(9)').parent.children('span:eq(1)').children('div:first').css("opacity", "1");

Here the value in first eq selector has to be variable as per the request

I obtained the value in a javascript variable called req and then I used this, but it shows ERROR

$('.win7red:eq(req)').parent.children('span:eq(1)').children('div:first').css("opacity", "1");

I even tried this, but none of them worked

$var = $('.win7red');
$var1 = $var:eq(req); 
$var1.parent.children('span:eq(1)').children('div:first').css("opacity", "1");

Please help in solving this problem.

1 Answer 1

5

Use parent() as a function instead of a property.

So, $('.win7red:eq(9)').parent( ) ...

Using .parent without parentheses can only be used at DOM objects, such as $("body").get(0).parentNode (=$("body").parent()).

Sign up to request clarification or add additional context in comments.

2 Comments

Ohh... typing mistake.. While writing code I mistakely wrote parent and never even cared....Thanks a lot :)
It’s actually parentNode and not parent when traversing DOM nodes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.