Using element on contentEditable requires two clicks for the first editHow do I detect a click outside an element?Javascript newbie - seems that onBlur of one element is “overriding” the onclick of anotherBoolean on empty contenteditable element evaluates to truehow to stop element with first onclick event to be fired when enter key is pressed first timeFocus a contenteditable div after double clicking on itManually Edit contenteditable Source HTMLonclick trigger doesn't work first clickHow to bypass two clicks needed to blur contenteditable div and click on outside button?Set contentEditable=“true” only for the div which is clicked and false for the restHow can I delete an editable div by clicking on it and then pressing the Delete key on the keyboard with Jquery?
Is there a hemisphere-neutral way of specifying a season?
What's the meaning of "Sollensaussagen"?
How do conventional missiles fly?
Sums of two squares in arithmetic progressions
Can compressed videos be decoded back to their uncompresed original format?
Am I breaking OOP practice with this architecture?
Can I hook these wires up to find the connection to a dead outlet?
Can someone clarify Hamming's notion of important problems in relation to modern academia?
Avoiding the "not like other girls" trope?
What historical events would have to change in order to make 19th century "steampunk" technology possible?
Why didn't Boeing produce its own regional jet?
Why was the shrink from 8″ made only to 5.25″ and not smaller (4″ or less)
Finitely generated matrix groups whose eigenvalues are all algebraic
Is it a bad idea to plug the other end of ESD strap to wall ground?
ssTTsSTtRrriinInnnnNNNIiinngg
Do creatures with a listed speed of "0 ft., fly 30 ft. (hover)" ever touch the ground?
Knowledge-based authentication using Domain-driven Design in C#
Fair gambler's ruin problem intuition
Does the Cone of Cold spell freeze water?
What are the G forces leaving Earth orbit?
Is it "common practice in Fourier transform spectroscopy to multiply the measured interferogram by an apodizing function"? If so, why?
Why are UK visa biometrics appointments suspended at USCIS Application Support Centers?
How dangerous is XSS
Different meanings of こわい
Using element on contentEditable requires two clicks for the first edit
How do I detect a click outside an element?Javascript newbie - seems that onBlur of one element is “overriding” the onclick of anotherBoolean on empty contenteditable element evaluates to truehow to stop element with first onclick event to be fired when enter key is pressed first timeFocus a contenteditable div after double clicking on itManually Edit contenteditable Source HTMLonclick trigger doesn't work first clickHow to bypass two clicks needed to blur contenteditable div and click on outside button?Set contentEditable=“true” only for the div which is clicked and false for the restHow can I delete an editable div by clicking on it and then pressing the Delete key on the keyboard with Jquery?
I'm trying to edit data held in a table and choosing to use contentEditable on divs inside the <td>
s, and I'm running into a really weird issue. When I go to edit it the first time, I have to click in twice, every other time after that I only have to click in once. But on the first attempt to edit I have to click in twice. Here is an example table row from my HTML:
<tr style="width:100%"> <td><div class="results" onblur="blurMe(event)" onclick="darkenBox(event)" onkeypress="enterKey(event)" >Adam McGurk</div></td><td><div class="results" onblur="blurMe(event)" onkeypress="enterKey(event)" onclick="darkenBox(event)">amcgurk@shinesolar.com</div></td><td class="delete-sales-person"><span class="delete-icon"></span></td></tr>
And here is the appropriate JS:
//Only to be used with changing data to gray on click and border on hover.
function darkenBox(e)
const ele = e.path[0];
ele.setAttribute("contenteditable", true);
console.log("Editing cell data");
ele.classList.add("darkenBox")
// Allows user to edit content by click
function clickEdit(e)
e.path[0].setAttribute("contenteditable", true);
//Deleted placeholder text on click
function clearText(e)
const ele = e.path[0];
ele.setAttribute("contenteditable", true);
ele.innerText='';
// Allows user to stop editing by pressing the, "Enter" key.
function enterKey(e)
const keyCode = e.keyCode;
const ele = e.path[0];
if (keyCode === 13)
ele.classList.remove("darkenBox");
ele.setAttribute("contenteditable", false);
function blurMe(e)
const editedElement = e.path[0];
editedElement.classList.remove("darkenBox");
Why is it requiring me to click it twice to edit the first time?
javascript contenteditable
add a comment |
I'm trying to edit data held in a table and choosing to use contentEditable on divs inside the <td>
s, and I'm running into a really weird issue. When I go to edit it the first time, I have to click in twice, every other time after that I only have to click in once. But on the first attempt to edit I have to click in twice. Here is an example table row from my HTML:
<tr style="width:100%"> <td><div class="results" onblur="blurMe(event)" onclick="darkenBox(event)" onkeypress="enterKey(event)" >Adam McGurk</div></td><td><div class="results" onblur="blurMe(event)" onkeypress="enterKey(event)" onclick="darkenBox(event)">amcgurk@shinesolar.com</div></td><td class="delete-sales-person"><span class="delete-icon"></span></td></tr>
And here is the appropriate JS:
//Only to be used with changing data to gray on click and border on hover.
function darkenBox(e)
const ele = e.path[0];
ele.setAttribute("contenteditable", true);
console.log("Editing cell data");
ele.classList.add("darkenBox")
// Allows user to edit content by click
function clickEdit(e)
e.path[0].setAttribute("contenteditable", true);
//Deleted placeholder text on click
function clearText(e)
const ele = e.path[0];
ele.setAttribute("contenteditable", true);
ele.innerText='';
// Allows user to stop editing by pressing the, "Enter" key.
function enterKey(e)
const keyCode = e.keyCode;
const ele = e.path[0];
if (keyCode === 13)
ele.classList.remove("darkenBox");
ele.setAttribute("contenteditable", false);
function blurMe(e)
const editedElement = e.path[0];
editedElement.classList.remove("darkenBox");
Why is it requiring me to click it twice to edit the first time?
javascript contenteditable
add a comment |
I'm trying to edit data held in a table and choosing to use contentEditable on divs inside the <td>
s, and I'm running into a really weird issue. When I go to edit it the first time, I have to click in twice, every other time after that I only have to click in once. But on the first attempt to edit I have to click in twice. Here is an example table row from my HTML:
<tr style="width:100%"> <td><div class="results" onblur="blurMe(event)" onclick="darkenBox(event)" onkeypress="enterKey(event)" >Adam McGurk</div></td><td><div class="results" onblur="blurMe(event)" onkeypress="enterKey(event)" onclick="darkenBox(event)">amcgurk@shinesolar.com</div></td><td class="delete-sales-person"><span class="delete-icon"></span></td></tr>
And here is the appropriate JS:
//Only to be used with changing data to gray on click and border on hover.
function darkenBox(e)
const ele = e.path[0];
ele.setAttribute("contenteditable", true);
console.log("Editing cell data");
ele.classList.add("darkenBox")
// Allows user to edit content by click
function clickEdit(e)
e.path[0].setAttribute("contenteditable", true);
//Deleted placeholder text on click
function clearText(e)
const ele = e.path[0];
ele.setAttribute("contenteditable", true);
ele.innerText='';
// Allows user to stop editing by pressing the, "Enter" key.
function enterKey(e)
const keyCode = e.keyCode;
const ele = e.path[0];
if (keyCode === 13)
ele.classList.remove("darkenBox");
ele.setAttribute("contenteditable", false);
function blurMe(e)
const editedElement = e.path[0];
editedElement.classList.remove("darkenBox");
Why is it requiring me to click it twice to edit the first time?
javascript contenteditable
I'm trying to edit data held in a table and choosing to use contentEditable on divs inside the <td>
s, and I'm running into a really weird issue. When I go to edit it the first time, I have to click in twice, every other time after that I only have to click in once. But on the first attempt to edit I have to click in twice. Here is an example table row from my HTML:
<tr style="width:100%"> <td><div class="results" onblur="blurMe(event)" onclick="darkenBox(event)" onkeypress="enterKey(event)" >Adam McGurk</div></td><td><div class="results" onblur="blurMe(event)" onkeypress="enterKey(event)" onclick="darkenBox(event)">amcgurk@shinesolar.com</div></td><td class="delete-sales-person"><span class="delete-icon"></span></td></tr>
And here is the appropriate JS:
//Only to be used with changing data to gray on click and border on hover.
function darkenBox(e)
const ele = e.path[0];
ele.setAttribute("contenteditable", true);
console.log("Editing cell data");
ele.classList.add("darkenBox")
// Allows user to edit content by click
function clickEdit(e)
e.path[0].setAttribute("contenteditable", true);
//Deleted placeholder text on click
function clearText(e)
const ele = e.path[0];
ele.setAttribute("contenteditable", true);
ele.innerText='';
// Allows user to stop editing by pressing the, "Enter" key.
function enterKey(e)
const keyCode = e.keyCode;
const ele = e.path[0];
if (keyCode === 13)
ele.classList.remove("darkenBox");
ele.setAttribute("contenteditable", false);
function blurMe(e)
const editedElement = e.path[0];
editedElement.classList.remove("darkenBox");
Why is it requiring me to click it twice to edit the first time?
javascript contenteditable
javascript contenteditable
asked Mar 21 at 20:29
Adam McGurkAdam McGurk
416420
416420
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Your divs start without contenteditable set. When you click on them (the first time) you set contenteditable to true, but the click is already handled so it won’t trigger an edit.
Only on the next click is the browser gonna allow for edit as now contenteditable is true.
Set contenteditable to true directly in the html and should work.
add a comment |
The first time you click it, it sets contenteditable
to true
. Clicking away doesn't unset that. The second time you click, contenteditable
is still true
. This allows you to activate the element and edit it right away. If you want to edit it on the first click, you can have all elements you intend to edit start with contenteditable
enabled. Or, you can focus the element after enabling contenteditable
.
ele.setAttribute("contenteditable", true);
ele.focus();
On an unrelated note, this currently doesn't work at all on firefox and I recommend that you use e.target
instead of e.path[0]
.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55288791%2fusing-element-on-contenteditable-requires-two-clicks-for-the-first-edit%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your divs start without contenteditable set. When you click on them (the first time) you set contenteditable to true, but the click is already handled so it won’t trigger an edit.
Only on the next click is the browser gonna allow for edit as now contenteditable is true.
Set contenteditable to true directly in the html and should work.
add a comment |
Your divs start without contenteditable set. When you click on them (the first time) you set contenteditable to true, but the click is already handled so it won’t trigger an edit.
Only on the next click is the browser gonna allow for edit as now contenteditable is true.
Set contenteditable to true directly in the html and should work.
add a comment |
Your divs start without contenteditable set. When you click on them (the first time) you set contenteditable to true, but the click is already handled so it won’t trigger an edit.
Only on the next click is the browser gonna allow for edit as now contenteditable is true.
Set contenteditable to true directly in the html and should work.
Your divs start without contenteditable set. When you click on them (the first time) you set contenteditable to true, but the click is already handled so it won’t trigger an edit.
Only on the next click is the browser gonna allow for edit as now contenteditable is true.
Set contenteditable to true directly in the html and should work.
answered Mar 21 at 21:09
Radu DițăRadu Diță
4,24811321
4,24811321
add a comment |
add a comment |
The first time you click it, it sets contenteditable
to true
. Clicking away doesn't unset that. The second time you click, contenteditable
is still true
. This allows you to activate the element and edit it right away. If you want to edit it on the first click, you can have all elements you intend to edit start with contenteditable
enabled. Or, you can focus the element after enabling contenteditable
.
ele.setAttribute("contenteditable", true);
ele.focus();
On an unrelated note, this currently doesn't work at all on firefox and I recommend that you use e.target
instead of e.path[0]
.
add a comment |
The first time you click it, it sets contenteditable
to true
. Clicking away doesn't unset that. The second time you click, contenteditable
is still true
. This allows you to activate the element and edit it right away. If you want to edit it on the first click, you can have all elements you intend to edit start with contenteditable
enabled. Or, you can focus the element after enabling contenteditable
.
ele.setAttribute("contenteditable", true);
ele.focus();
On an unrelated note, this currently doesn't work at all on firefox and I recommend that you use e.target
instead of e.path[0]
.
add a comment |
The first time you click it, it sets contenteditable
to true
. Clicking away doesn't unset that. The second time you click, contenteditable
is still true
. This allows you to activate the element and edit it right away. If you want to edit it on the first click, you can have all elements you intend to edit start with contenteditable
enabled. Or, you can focus the element after enabling contenteditable
.
ele.setAttribute("contenteditable", true);
ele.focus();
On an unrelated note, this currently doesn't work at all on firefox and I recommend that you use e.target
instead of e.path[0]
.
The first time you click it, it sets contenteditable
to true
. Clicking away doesn't unset that. The second time you click, contenteditable
is still true
. This allows you to activate the element and edit it right away. If you want to edit it on the first click, you can have all elements you intend to edit start with contenteditable
enabled. Or, you can focus the element after enabling contenteditable
.
ele.setAttribute("contenteditable", true);
ele.focus();
On an unrelated note, this currently doesn't work at all on firefox and I recommend that you use e.target
instead of e.path[0]
.
answered Mar 21 at 21:14
CoryCoolguyCoryCoolguy
276
276
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55288791%2fusing-element-on-contenteditable-requires-two-clicks-for-the-first-edit%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown