views:

56

answers:

2

I have a table cell with a text box in it, and I'm trying to take the value of the text box and put it back into the table cell while removing the text box. I'm doing this for a while row. So I have this:

        tds.each(function(i) {
            var val = $(this).children('input').eq(0).val();
            document.getElementById($(this).attr('id')).innerHTML = val;
            //$(this).html(val);
            //$(this).text(val);
        });

As you can see, I tried a few different ways, and with all of them, nothing happens. I don't get any errors either. Not sure whats going on.

+3  A: 

Try:

var tds = $('#table_id td');

tds.each(function(i) {
   var val = $(this).children(':input:eq(0)').val();
   $(this).html(val);
});
Sarfraz
$(this)html(val) should be $(this).html(val) - this works for me as well though.
ryanulit
+1 I'd also mention a possible reason - the implicit `tbody` insertion into the table which might be causing `tds` to be empty in the first place.
Anurag
@Anurag: Yeah that's right, we leave it to the OP to confirm after reading your comment :)
Sarfraz
Hrm, this doesn't seem to work either.
The.Anti.9
@The.Anti.9: What error do you get? Also post your html markup.
Sarfraz
+4  A: 

Have you verified that the collection tds has any items in it? Whenever nothing happens and an error is not thrown, I look at the jQuery selector first.

KingErroneous