2

See my code:

var ths = $("#my_table table th");
if (ths.length > 1) {
    var $th = ths[1]; // tried here plain 'var th' - still got error 
    th.find('#map_column_element_id'); // error here!
}

I get array of JQuery objects. Then I try to manage the second element as JQuery object. When I issue

th.find(...)

I get TypeError: th.find is not a function. What am I doing wrong?

1
  • 2
    Why would you need to find an element by its id? ids should be unique on the page so $("#map_column_element_id") should be fine. Commented Dec 21, 2012 at 16:09

1 Answer 1

6

You're getting the native JS DOM element, which doesn't have a find() method. Use eq(), or rewrap the element with $(ths[1]).

I'd use eq(), like so:

var ths = $("#my_table table th");
if (ths.length > 1) {
    var $th = ths.eq(1);
    $th.find('#map_column_element_id');
}

Also agree with Andrew in the comment, an ID is unique, and there should be no need to find() it, simply doing $('#map_column_element_id') should suffice.

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

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.