I have a classic table / thead / tbody
structure, which I add a line at the end of the tbody. The line contains only an input
element. The code works in Firefox 3.6 but not in Chrome v5 or IE8. I'm using jQuery 1.4.2.
Does not work:
$("#" + AJAX_ID).parent().find('tr:last > td:nth-child(2) > input').focus();
Does work:
$("#" + AJAX_ID).parent().find('tr:last > td:nth-child(2) > input').css('background-color', 'red');
even setting an ID on the input, and using document.getElementBuId('id').focus()
doesn't work.
Thank you!
* edit *
the site is pretty complex (mix of template / static html and dynamic html), but the table looks like this (rendered html in chrome, layout via tidy) : http://pastebin.com/PHqxAEVm
* edit 2 *
even $("#lectures").find("input:last").focus();
called from the ajax callback doesn't do anything.. $("#lectures").find("input:last").css('background-color', 'red');
turns one red though, but the focus goes to the address bar.
here's a dump of the returned object from the selector: http://pastebin.com/Jdw1TZXf
* edit 3 *
here's the javascript code that builds the table: http://pastebin.com/cbCfi0UY
on page load, oContainer
is $("#lectures")
while after the ajax call it's $("#" + AJAX_ID).parent()
, which is supposed to point to the table's tbody
* edit 4 *
hard problem... here's the full lectures.js
file: http://pastebin.com/Jkg0DZqa
batisses
and compteurs
are json objects loaded via the template. the user select a batisse
then a compteur
then press a button that calls buildAjout()
, which calls in this exemple buildElectric($("#lectures"), compteur);
. Once the line is filled bu the user, onBlurLecture(tr_parent)
is called, the data is sent to the server via AJAX and function callback_compteurs_lecture_add(AJAX_ID)
is called after the ajax call is complete. The function SendCommand
is a custom function which use jquery ajax.
The creation of the first input line (and the focus) works, but not the one created in the callback of the ajax.
* edit 5 *
the full rendered page looks like: http://pastebin.com/UfBYcjX3
I shortened the batisses
variable. The (full) page has no javascript errors.
In chrome's javascript console, I cannot focus the inputs.
* edit 6 *
wrong function name in this question for SendCommand
. fixed.
solution found: http://bit.ly/bHd6nH