j6m8
j6m8

Reputation: 2409

How can I retain `contenteditable` focus() events in a Meteor template?

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.

Upvotes: 0

Views: 292

Answers (1)

Jim Mack
Jim Mack

Reputation: 1437

Place focus code into Template.blah.rendered.

Upvotes: 1

Related Questions