3

Everytime I click a div or I focus on a contenteditable div it highlights the text I've clicked. This is not the case for other sites I have tried so I know it's not my mouse, I have a fair amount of jquery and css so I don't think it's useful to post all the code. Could people provide suggestions/speculation to why it's doing this and how it could be fixed because at the moment I have no idea.. I have no specific code to highlight any text so I'm 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>
Wickey312
  • 566
  • 5
  • 15
  • Can you clarify which part do you want to select? On your code looks like you are trying to select the element of dom like the "p" container of a text – Manjar Jun 20 '15 at 11:40
  • Do you click on the text inside the div?Also your click handler is also fired for both body and input box – Mohit Jun 20 '15 at 11:41
  • @Balder - I don't want the text highlighted when I click stuff.. it highlights the individual letter when you click the box.. Mohit, Yes i do click on the text, if you click anything it seems to highlight it, so if there's text there it'll highlight the text.. if theres nothing there it'll highlight the div itself.. I don't mind if it fires for body and input box, unless there's a more efficient way you can think of (I need to detect everytime anything is clicked).. – Wickey312 Jun 20 '15 at 21:05

2 Answers2

0

You can try

window.getSelection().removeAllRanges();

document.getSelection().removeAllRanges();

To make sure all your text is not selected.

Please take a look at these two entries:

How can I deselect text using Javascript or jQuery?

Select/Unselect Text on click Using jQuery

Community
  • 1
  • 1
guergana
  • 374
  • 5
  • 19
  • This is a good idea but not what I need.. for a split second it still shows the highlighted text / div which is not normal behaviour.. – Wickey312 Jun 20 '15 at 21:06
0

So I think this is actually a bug in chrome. After leaving it a few hours and then refreshing the page, it randomly started working with normal functionality. Thank you to everyone who attempted to help - guergana presents a possible solution if you have stumbled across this page looking for answers.

Wickey312
  • 566
  • 5
  • 15