0

see this code

$(function() {
    $('.do').deleteTable({
        parent: $(".do").parentsUntil("#did")

    });
});

its works but if i make it

$(function() {
$('.do').deleteTable({
parent: $(this).parentsUntil("#did")
});
});

not works; why? i replace $(".do") to $(this)

1
  • ...you don't need to wrap this in $(). Commented Mar 4, 2010 at 13:54

4 Answers 4

4

{ parent: $(this).parentsUntil("#did") } is an object literal, calculated before it is passed to deleteTable.

It is not a function called back from deleteTable with this set to each element with class do.

So this is the outer function() { ... }'s this: namely window.

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

Comments

2

This may help...

'this' demystified

Comments

1

"this" is probably the "window" object, which won't have parents.

I'm guessing you're thinking of a situation as follows:

$(function() {
    $('.do').click(function() {
    alert($(this).is('.do'));
    });
});

In the above case, when the function is run because of a click event, then "this" will be the $('.do') object you expect it to be. In your case however, the context of "this" is not $('.do')

Comments

1

When I'm in a similar situation, the first thing I do is set up a breakpoint and check (using firebug for example) if the $(this) is really what I'm expecting.

99% of the time that helps me understand what's going on.

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.