0

I'm having a problem that if I click and trigger this function the focus appear before the image.
I can write and click to add the image bue if I continue writing it will be before the image xd so I need it to focus after the image, is that possible?

message = "<img src='emotions-fb/" + chatboxtitle +".png' title='" + chatboxtitle + "' class='embtn'/>";

$("#chatFrom .chatboxtextarea").append(message);
$('#chatFrom .chatboxtextarea').focus();
adeneo
  • 312,895
  • 29
  • 395
  • 388
  • 2
    The image is appended before the element is focused. Maybe it just needs some time to load, given that it's an image. – adeneo Jul 01 '17 at 22:05
  • Maybe this answer can help you too? https://stackoverflow.com/questions/4233265/contenteditable-set-caret-at-the-end-of-the-text-cross-browser/4238971#4238971 – CdB Jul 01 '17 at 22:17
  • Like what @adeneo said, you probably want to preload the image first. Once it is preloaded/fetched from cache, you then trigger the focus method. – Terry Jul 01 '17 at 22:18

0 Answers0