Skip to content Skip to sidebar Skip to footer

JQuery: Array[i].children() Is Not A Function

The following code is inspired by http://ignorethecode.net/blog/2010/04/20/footnotes/: when you move the cursor over the footnote symbol, the footnote is shown as a tool-tip.

Solution 1:

  1. var sup = $fRef.children("sup")[i];
    takes the ith element in the collection of children of $fRef;
    All the other methods deals with the ith element of the $fRef collection:

  2. var sup = $fRef[i].children("sup");
    tries to call the function children on the ith element of the jQuery collection $fRef, but that element is a classic Dom Element so it doesn't have any children method.

  3. var sup = $fRef.eq(i).children("sup");
    does the same thing as 2 but correctly as eq will return a jQuery object. It retrieves all the children of the ith element of $rFref

  4. var sup = $fRef.get(i).children("sup");
    The get method does the same as the index: it gets the dom object so it won't work either.

  5. var sup = $($fRef[i]).children("sup");
    will also work as 3 as you rewrap the html collection in a dom element. It's really unefficient though


Post a Comment for "JQuery: Array[i].children() Is Not A Function"