0

I'm writing a very simple WYSIWYG editor using javascript

When I use the following it adds the link to the div

   link.addEventListener("click", function () {
        var name = prompt("Enter the text");
        var url = prompt("Enter the URL", "http://");
        update("insertHTML", "<a href=" + url +">"+name+"</a>");
    });


function update(cmd, param){
    document.execCommand(cmd, false, param);
}

This works according to inspectElement in Chrome tools, but, I can't click on it.

Is it possible to make this clickable?

MyDaftQuestions
  • 4,487
  • 17
  • 63
  • 120
  • 2
    Maybe not the solution, but it's considered best practice to use quotes with tag parameters (i.e. `href="http://..."`), so `update("insertHTML", ""+name+"");` – WOUNDEDStevenJones Jan 24 '17 at 21:09
  • @WOUNDEDStevenJones, thank you for the comment, but I'm not sure *why* this is good / better / best. What I had was working, but, I assume there are cases where it wouldn't? – MyDaftQuestions Jan 24 '17 at 21:21
  • 1
    Comes down to maintainability, cleanliness, consistency, etc. https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=html+attribute+quotes has a number of SO articles about it that all suggest you should always quote, but not using quotes won't necessarily break any functionality. – WOUNDEDStevenJones Jan 24 '17 at 21:38
  • Did that help fix anything? Otherwise I'd look into some other javascript options - possibly http://stackoverflow.com/questions/8005694/make-hyperlink-from-javascript or http://stackoverflow.com/questions/4772774/how-do-i-create-a-link-using-javascript. If you're using jQuery at all check out https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=jquery%20insert%20a%20link – WOUNDEDStevenJones Jan 24 '17 at 21:46
  • The "fix" makes no difference – MyDaftQuestions Jan 25 '17 at 09:39

0 Answers0