0

I have a <div contenteditable class="content"> </div> in my template whose inner HTML is tied to Mongo. When I (dynamically) add a new .content, I'd like to be able to focus it so that the next thing a user types is entered in the contenteditable div.

However, the .focus() event doesn't play nicely with Meteor's rerendering; even SO's hacks don't work: The JS executes without error, but the focus event doesn't seem to trigger anything (or, it does but it's immediately overwritten by Meteor's rendering).

My question is: How can I force focus that div? A plan I considered was setting a tabindex and then artificially tabbing to that element, but I'm hoping to not have to resort to such silliness.

[EDIT] I'm aware of the {{#constant}} tag, but as far as I can tell, that stops the element from being rerendered at all, which is certainly not what I want.

Community
  • 1
  • 1
j6m8
  • 2,261
  • 2
  • 26
  • 34

1 Answers1

1

Place focus code into Template.blah.rendered.

Jim Mack
  • 1,437
  • 11
  • 16
  • Took me a moment to realize that `this` isn't the `this` I was necessarily expecting... But a single line of jquery later, this is far more functional than I was even hoping. Thank you! – j6m8 Sep 17 '13 at 00:50
  • @j6m8 will you please post a working example of this? We are looking for a similar solution. – Brylie Christopher Oxley Feb 09 '15 at 09:50