Editable Div - Key Features

Every time I click on a div or I focus on the contenteditable div, it will highlight the text I clicked on. This is not the case with other sites I have tried, so I know this is not my mouse, I have a fair amount of jquery and css, so I don't think it's helpful to post all the code. Can people offer suggestions / speculations, why they do it, and how they can be corrected, because at the moment I have no idea. I don't have any special code to highlight any text, so I am very confused.

enter image description here

Relevant code:

 //This is loaded on body load
 $("body").click(function(el) {
            if($("#menu").is(":visible")){
               //The click handler function puts new textboxes in if clicked correctly.
              clickHandler($(event.target));
 }


 <div class="container image">
    <img src="https://placeimg.com/240/180/any" />
</div>

      

+3


source to share


2 answers


You may try

window.getSelection().removeAllRanges();

document.getSelection().removeAllRanges();

      

To make sure all text is not selected.



Please take a look at these two entries:

How can I deselect text using Javascript or jQuery?

Select / Deselect text on click Using jQuery

0


source


So, I think this is actually a bug in chrome. Leaving this after a few hours and then refreshing the page, it accidentally started working with normal functionality. Thanks to everyone who tried to help - guergana presents a possible solution if you stumbled across this page looking for answers.



0


source







All Articles