admin管理员组

文章数量:1305711

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'));

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'));
Share Improve this question asked Apr 7, 2010 at 8:41 firefire 21.5k18 gold badges82 silver badges116 bronze badges 0
Add a ment  | 

3 Answers 3

Reset to default 6
$("<img/>", {
  src:  "img/loading.gif",
  id:   "loading_img"
}).insertAfter($("form").find("input:last"));

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.

Try this:

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

本文标签: javascriptjQuery find last input and appendStack Overflow