1

I have a quick question. I don't know why this is not working. I am using a variable name instead the id.

var navWrapper = $('#nav');
var headParentUL = $(this).parents(navWrapper + ' > ul');

Thanks for the help.

2
  • I'd need to test in order to find out what results when you add a string to an object but, most likely, it isn't a CSS selector. Commented Jan 23, 2014 at 15:47
  • see jsfiddle.net/arunpjohny/3e93r/1 Commented Jan 23, 2014 at 15:53

2 Answers 2

1

Put id in variable instead of jQuery object

var navWrapper = '#nav';
var headParentUL = $(this).parents(navWrapper + ' > ul');
Sign up to request clarification or add additional context in comments.

1 Comment

Does it work if you do not use variable? also show us the html
0

Using an Object wont work.

Option 1:

var navWrapper = '#nav';
var headParentUL = $(this).parents(navWrapper + ' > ul');

Option 2:

var navWrapper = $('#nav');
var headParentUL = $(this).parents(navWrapper.attr('id') + ' > ul');

Option 3:

var navWrapper = $('#nav');
var headParentUL = $(this).parents(navWrapper).children('ul');

Comments

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.