How to make a link button contenteditable
On my website, I have a link using role=button
with Bootstrap's btn btn-primary
. When I try to assign the contenteditable
attribute to the button, it does not work as expected and does not allow me to edit it.
Things I have tried :
Disable dragging for link button
Make link button focused after having
contenteditable
set.Remove all links from the button
javascript html
add a comment |
On my website, I have a link using role=button
with Bootstrap's btn btn-primary
. When I try to assign the contenteditable
attribute to the button, it does not work as expected and does not allow me to edit it.
Things I have tried :
Disable dragging for link button
Make link button focused after having
contenteditable
set.Remove all links from the button
javascript html
It would be helpful if someone were to explain the downvotes!
– AutoBootDisk
Nov 22 '18 at 3:20
add a comment |
On my website, I have a link using role=button
with Bootstrap's btn btn-primary
. When I try to assign the contenteditable
attribute to the button, it does not work as expected and does not allow me to edit it.
Things I have tried :
Disable dragging for link button
Make link button focused after having
contenteditable
set.Remove all links from the button
javascript html
On my website, I have a link using role=button
with Bootstrap's btn btn-primary
. When I try to assign the contenteditable
attribute to the button, it does not work as expected and does not allow me to edit it.
Things I have tried :
Disable dragging for link button
Make link button focused after having
contenteditable
set.Remove all links from the button
javascript html
javascript html
asked Nov 22 '18 at 2:41
AutoBootDiskAutoBootDisk
6813
6813
It would be helpful if someone were to explain the downvotes!
– AutoBootDisk
Nov 22 '18 at 3:20
add a comment |
It would be helpful if someone were to explain the downvotes!
– AutoBootDisk
Nov 22 '18 at 3:20
It would be helpful if someone were to explain the downvotes!
– AutoBootDisk
Nov 22 '18 at 3:20
It would be helpful if someone were to explain the downvotes!
– AutoBootDisk
Nov 22 '18 at 3:20
add a comment |
1 Answer
1
active
oldest
votes
Try this:
<button id="editBtn" type="button">Click to edit me</button>
JQuery:
$('#editBtn').on('click', function(e) {
e.preventDefault();
$(this).attr('contenteditable','true');
//$(this).focus();
return;
});
$('#editBtn').on('focus', function(e){
console.log("blurred...");
$(this).attr('contenteditable','false');
});
JS:
document.getElementsById("editBtn").contentEditable = "true";
or
document.getElementsById("editBtn").setAttribute("contenteditable", "true");
is it possible to do so without jquery?
– AutoBootDisk
Nov 22 '18 at 3:13
you want only JS?
– Wal
Nov 26 '18 at 2:20
yes only JS....
– AutoBootDisk
Nov 26 '18 at 21:23
Try with: document.getElementsById("your_button_id").contentEditable = "true"; or document.getElementsById("your_button_id").setAttribute("contenteditable", "true"); (I edit my reply with the new js) Hope it can help you
– Wal
Nov 27 '18 at 1:55
Not what I was looking for but i will mark it as correct anyway. What I actually meant was that the cotenteditable tag has weird selections. Check my profile for a new question containing more details.
– AutoBootDisk
Nov 27 '18 at 3:08
|
show 1 more 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%2f53423144%2fhow-to-make-a-link-button-contenteditable%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Try this:
<button id="editBtn" type="button">Click to edit me</button>
JQuery:
$('#editBtn').on('click', function(e) {
e.preventDefault();
$(this).attr('contenteditable','true');
//$(this).focus();
return;
});
$('#editBtn').on('focus', function(e){
console.log("blurred...");
$(this).attr('contenteditable','false');
});
JS:
document.getElementsById("editBtn").contentEditable = "true";
or
document.getElementsById("editBtn").setAttribute("contenteditable", "true");
is it possible to do so without jquery?
– AutoBootDisk
Nov 22 '18 at 3:13
you want only JS?
– Wal
Nov 26 '18 at 2:20
yes only JS....
– AutoBootDisk
Nov 26 '18 at 21:23
Try with: document.getElementsById("your_button_id").contentEditable = "true"; or document.getElementsById("your_button_id").setAttribute("contenteditable", "true"); (I edit my reply with the new js) Hope it can help you
– Wal
Nov 27 '18 at 1:55
Not what I was looking for but i will mark it as correct anyway. What I actually meant was that the cotenteditable tag has weird selections. Check my profile for a new question containing more details.
– AutoBootDisk
Nov 27 '18 at 3:08
|
show 1 more comment
Try this:
<button id="editBtn" type="button">Click to edit me</button>
JQuery:
$('#editBtn').on('click', function(e) {
e.preventDefault();
$(this).attr('contenteditable','true');
//$(this).focus();
return;
});
$('#editBtn').on('focus', function(e){
console.log("blurred...");
$(this).attr('contenteditable','false');
});
JS:
document.getElementsById("editBtn").contentEditable = "true";
or
document.getElementsById("editBtn").setAttribute("contenteditable", "true");
is it possible to do so without jquery?
– AutoBootDisk
Nov 22 '18 at 3:13
you want only JS?
– Wal
Nov 26 '18 at 2:20
yes only JS....
– AutoBootDisk
Nov 26 '18 at 21:23
Try with: document.getElementsById("your_button_id").contentEditable = "true"; or document.getElementsById("your_button_id").setAttribute("contenteditable", "true"); (I edit my reply with the new js) Hope it can help you
– Wal
Nov 27 '18 at 1:55
Not what I was looking for but i will mark it as correct anyway. What I actually meant was that the cotenteditable tag has weird selections. Check my profile for a new question containing more details.
– AutoBootDisk
Nov 27 '18 at 3:08
|
show 1 more comment
Try this:
<button id="editBtn" type="button">Click to edit me</button>
JQuery:
$('#editBtn').on('click', function(e) {
e.preventDefault();
$(this).attr('contenteditable','true');
//$(this).focus();
return;
});
$('#editBtn').on('focus', function(e){
console.log("blurred...");
$(this).attr('contenteditable','false');
});
JS:
document.getElementsById("editBtn").contentEditable = "true";
or
document.getElementsById("editBtn").setAttribute("contenteditable", "true");
Try this:
<button id="editBtn" type="button">Click to edit me</button>
JQuery:
$('#editBtn').on('click', function(e) {
e.preventDefault();
$(this).attr('contenteditable','true');
//$(this).focus();
return;
});
$('#editBtn').on('focus', function(e){
console.log("blurred...");
$(this).attr('contenteditable','false');
});
JS:
document.getElementsById("editBtn").contentEditable = "true";
or
document.getElementsById("editBtn").setAttribute("contenteditable", "true");
edited Nov 27 '18 at 1:56
answered Nov 22 '18 at 2:44
WalWal
538
538
is it possible to do so without jquery?
– AutoBootDisk
Nov 22 '18 at 3:13
you want only JS?
– Wal
Nov 26 '18 at 2:20
yes only JS....
– AutoBootDisk
Nov 26 '18 at 21:23
Try with: document.getElementsById("your_button_id").contentEditable = "true"; or document.getElementsById("your_button_id").setAttribute("contenteditable", "true"); (I edit my reply with the new js) Hope it can help you
– Wal
Nov 27 '18 at 1:55
Not what I was looking for but i will mark it as correct anyway. What I actually meant was that the cotenteditable tag has weird selections. Check my profile for a new question containing more details.
– AutoBootDisk
Nov 27 '18 at 3:08
|
show 1 more comment
is it possible to do so without jquery?
– AutoBootDisk
Nov 22 '18 at 3:13
you want only JS?
– Wal
Nov 26 '18 at 2:20
yes only JS....
– AutoBootDisk
Nov 26 '18 at 21:23
Try with: document.getElementsById("your_button_id").contentEditable = "true"; or document.getElementsById("your_button_id").setAttribute("contenteditable", "true"); (I edit my reply with the new js) Hope it can help you
– Wal
Nov 27 '18 at 1:55
Not what I was looking for but i will mark it as correct anyway. What I actually meant was that the cotenteditable tag has weird selections. Check my profile for a new question containing more details.
– AutoBootDisk
Nov 27 '18 at 3:08
is it possible to do so without jquery?
– AutoBootDisk
Nov 22 '18 at 3:13
is it possible to do so without jquery?
– AutoBootDisk
Nov 22 '18 at 3:13
you want only JS?
– Wal
Nov 26 '18 at 2:20
you want only JS?
– Wal
Nov 26 '18 at 2:20
yes only JS....
– AutoBootDisk
Nov 26 '18 at 21:23
yes only JS....
– AutoBootDisk
Nov 26 '18 at 21:23
Try with: document.getElementsById("your_button_id").contentEditable = "true"; or document.getElementsById("your_button_id").setAttribute("contenteditable", "true"); (I edit my reply with the new js) Hope it can help you
– Wal
Nov 27 '18 at 1:55
Try with: document.getElementsById("your_button_id").contentEditable = "true"; or document.getElementsById("your_button_id").setAttribute("contenteditable", "true"); (I edit my reply with the new js) Hope it can help you
– Wal
Nov 27 '18 at 1:55
Not what I was looking for but i will mark it as correct anyway. What I actually meant was that the cotenteditable tag has weird selections. Check my profile for a new question containing more details.
– AutoBootDisk
Nov 27 '18 at 3:08
Not what I was looking for but i will mark it as correct anyway. What I actually meant was that the cotenteditable tag has weird selections. Check my profile for a new question containing more details.
– AutoBootDisk
Nov 27 '18 at 3:08
|
show 1 more 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%2f53423144%2fhow-to-make-a-link-button-contenteditable%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
It would be helpful if someone were to explain the downvotes!
– AutoBootDisk
Nov 22 '18 at 3:20