views:

43

answers:

3

I am trying to append an image after the last input field in a div, any ideas as to why this won't work?

$('<img src="img/loading.gif" id="loading_img" />').appendTo($(form).find('input:last'));
+1  A: 

You must use the insertAfter function:

$('<img src="img/loading.gif" id="loading_img" />').insertAfter($("form").find('input:last'));

The append function adds the image INTO the input with insertAfter you insert the image AFTER the input.

mck89
+3  A: 
$("<img/>", {
  src:  "img/loading.gif",
  id:   "loading_img"
}).insertAfter($("form").find("input:last"));

Kind Regards

--Andy

jAndy
A: 

Try this:

$('<img src="img/loading.gif" id="loading_img" />').appendTo('#formid-here input:last'));
Sarfraz