[jQuery] Re: What is the proper way to write this if statement?

2010-01-13 Thread pedalpete
Everything that I've seen says you have to check the length of the element you are looking for. So I think you want pre if($(this).parents('ul').length==0){ $(this).addClass(active); } /pre If a parent UL was found, the length would be 0

Re: [jQuery] Re: What is the proper way to write this if statement?

2010-01-13 Thread Matt Maxwell
This is correct. I actually wrote a few jQuery extensions that handle this. The code is: $.fn.extend({ // checks to see if an element exists // if no callback is supplied, returns // a boolean value stating if the element // exists, otherwise executes the callback exists: function (callback) {

[jQuery] Re: What is the proper way to write this if statement?

2010-01-13 Thread RobG
On Jan 14, 11:00 am, Matt Maxwell leftwithoutli...@gmail.com wrote: [...] var that = this; // scope The value of the this keyword has nothing whatever to do with scope. -- Rob

[jQuery] Re: What is the proper way to write this if statement?

2010-01-13 Thread Scooby
Thanks guys!! Got it working.. On Jan 13, 7:00 pm, Matt Maxwell leftwithoutli...@gmail.com wrote: This is correct. I actually wrote a few jQuery extensions that handle this. The code is: $.fn.extend({ // checks to see if an element exists // if no callback is supplied, returns // a

Re: [jQuery] Re: What is the proper way to write this if statement?

2010-01-13 Thread Matt Maxwell
You're right. This was a small oversight on my end, though, it would have been a little more helpful to the OP if you had provided an explanation with your reply. :) The reason I use var that = this; is not for scope but rather to ensure that the proper object is being referenced inside the