0

I am trying to assign an object to another other in jQuery but I am getting error. I am quite new to jQuery so all helps are much appreciated. Following is the code i am trying to do.

 while ($(obj)) {

        $(obj) = $(obj).children(":first");

    }

It is trying to traverse through a table.

3
  • What does the error say? Commented Feb 22, 2012 at 13:50
  • You cannot assign to the return value of a function, so $(obj) = something; does not make much sense. Why not use a local obj variable instead? Commented Feb 22, 2012 at 13:51
  • Cannot assign to a function result Commented Feb 22, 2012 at 13:51

1 Answer 1

1

$(obj) will always be considered as true, you are doing an infinite loop.

At least, you should do while ($(obj).length), and you can't assign $(obj).children(":first") to $(obj), $(obj) is not a variable. So maybe what you want to do is like below.

var element = $(obj);
while (element.length) {
    element = element.children(":first");
}
Sign up to request clarification or add additional context in comments.

2 Comments

yes obj was making it a infinite loop . thanks i made it work
also one more quick question does it make sense if i assign obj = $(obj).children(":first"); ?

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.