How to make a link button contenteditable












-1















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








share|improve this question























  • It would be helpful if someone were to explain the downvotes!

    – AutoBootDisk
    Nov 22 '18 at 3:20
















-1















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








share|improve this question























  • It would be helpful if someone were to explain the downvotes!

    – AutoBootDisk
    Nov 22 '18 at 3:20














-1












-1








-1








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








share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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



















  • 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












1 Answer
1






active

oldest

votes


















0














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");





share|improve this answer


























  • 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











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
});


}
});














draft saved

draft discarded


















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









0














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");





share|improve this answer


























  • 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
















0














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");





share|improve this answer


























  • 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














0












0








0







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");





share|improve this answer















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");






share|improve this answer














share|improve this answer



share|improve this answer








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



















  • 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




















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

Origin of the phrase “under your belt”?