Matt
Matt

Reputation: 935

How do I put an element into contenteditable mode via javascript

I have the following HTML element

<p class="story" contenteditable="true">This is a story.</p>

Now I want to put the element into edit mode via javascript. I assumed something like the following would work, but it doesn't

$('.story').click();

How can I manually put this element in edit mode (via javascript or any other way) without the user clicking on the element?

Upvotes: 0

Views: 207

Answers (2)

Chris Sobolewski
Chris Sobolewski

Reputation: 12925

$('.story').focus(function(){
    $(this).attr('contenteditable', 'true');
});

Upvotes: -1

Plynx
Plynx

Reputation: 11461

Use focus instead of click:

$(".story").focus();

Upvotes: 3

Related Questions