0

Here is a code sample:

$('#TBI tr.k-state-selected')[0].cells[0].find("input").val(selectedId).change();

I'm actually trying the change the value of a cell on a KendoUI grid. But for some reason it's giving me an "Object does not support this method" on the .find.

If I do this:

$('#TBI tr.k-state-selected').find("input").val(selectedId).change();

It doesn't give me the error (but not the results I want either). When I take the array elements away, it seems fine from a syntax perspective.

So my question becomes: How do I do a find such as this when there are array elements involved.

1
  • Is .cells[0] a jQuery object? If not, try: $($('#TBI tr.k-state-selected')[0].cells[0]).find("input").val(selectedId).change(); Commented Sep 21, 2012 at 15:19

3 Answers 3

3

If I follow your pseudo code logic, you might want

$('#TBI tr.k-state-selected:eq(0) td:eq(0) input').val(selectedId).change();

that is :

the inputs in the first cell of the first row with class k-state-selected in the element of id TBI.

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

1 Comment

For the OP's benefit: also learn about :first and :nth-child. Those two plus :eq will help a lot if you're doing anything remotely complex with dom manipulation
1

I don't think cell[0] is a jQuery object so you wouldn't be able to call a jQuery method on it.

Try wrapping it into a jQuery object again

var $cell = $($('#TBI tr.k-state-selected')[0].cells[0]);

$cell.find("input").val(selectedId).change();

Or off course, fixing up your selector to return the desired element to begin with as in dystroy's answer would save the hassle of wrapping it again.

Comments

0

Try eq jquery function to get jquery object instead of getting javascript object by using [0]

Live Demo

$('#TBI tr.k-state-selected').eq(0).find("td:eq(0) input").val(selectedId).change();

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.