1

I'm having trouble understanding how to pass a jQuery object between functions. I keep getting undefined values when trying to use val after passing jQuery objects to a function.

Very simple JS Fiddle example http://jsfiddle.net/BtVqc/1/

$(document).ready(function () {
    function doSomething(objectOne, objectTwo) {
        $('table').append('<tr><td>' + objectOne.val() + '</td><td>' + objectTwo.val() + '</td></tr>');
    }

    $('button').click(function () {
        var tdOne = $('td.yy');
        var tdTwo = $('td.xx');
        doSomething(tdOne, tdTwo);
    });
});

1 Answer 1

5

The correct selector for the input is td .xx not td.xx

var tdOne = $('td .yy');
var tdTwo = $('td .xx');

http://jsfiddle.net/BtVqc/2/

td.xx means - a table cell that has xx class

td .xx means - some node that has xx class and is nested to a table cell

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.