0

Possible Duplicate:
Unselect what was selected in an input with .select()

I know there are functions for specific tags like option, checkbox etc.. but those are not the ones i am looking for.

I need reverse of this:

http://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_event_select_trigger

When i trigger the event the selected text, image, area should be unselected.

Is there a function like unselect ?

Problem can be seen here:

enter image description here

So far i have tried those but not worked:

jQuery('.es-nav-next, .es-nav-prev').click(function(){
    //    jQuery("btn btn-large btn-primary").focus();
    //  jQuery(this).stop(true, true).delay(600).hide().delay(600).fadeIn().blur();      
        jQuery("#falseselect").select();
        document.selection.emtpy();
    window.getSelection().empty();
    jQuery(this).blur();
    });
Community
  • 1
  • 1
mirza
  • 5,685
  • 10
  • 43
  • 73
  • @FelixKling i didn't said it was selected with .select() – mirza Oct 13 '12 at 10:18
  • It does not matter *how* the text was selected. You want to unselect the text, hence this question is a duplicate of the other one. I only picked that question because your example uses `.select` to select the text. The answer applies to your problem as well (because it's the same problem). – Felix Kling Oct 13 '12 at 10:26
  • @FelixKling i have added a gif file for showing the problem – mirza Oct 13 '12 at 10:40
  • @FelixKling: Blur only determines whether or not an element is focused, not whether there is a selection within it. I take it from the description "the selected text, image, area" that motto refers to any selection in the entire document. – David Hedlund Oct 13 '12 at 10:43
  • @DavidHedlund blur is not working too. – mirza Oct 13 '12 at 10:45
  • @motto: yes, that was my point. I think `window.getSelection().empty()` would do the trick for you, but then I've already answered that. – David Hedlund Oct 13 '12 at 10:58
  • @David: Alright, we can always vote to reopen, no big deal. I saw the description too of course, but I was focusing more on the example, which only shows an input element. A better description of the problem from the beginning would have made things easier (though I still think the question is not very clear...). – Felix Kling Oct 13 '12 at 17:06
  • What is `#falseselect` in your example? What are `.es-nav-next` and `.es-nav-prev`? Please provide a http://jsfiddle.net/ demo and explain what you want to happen and what currently happens. You want help from us, so please don't make it difficult for us to help you. – Felix Kling Oct 13 '12 at 17:07

3 Answers3

2

I don't know of a jQuery library that handles this, which means you'll have to worry about browser compatibilities yourself.

In most browsers, you should be able to run

window.getSelection().empty();

In problematic browsers, you might have to make that

document.selection.emtpy();
David Hedlund
  • 128,221
  • 31
  • 203
  • 222
  • @motto: "not working" is not a very helpful error description. What exactly are you doing and what do you expect to happen? Please create http://jsfiddle.net/ demo for us and explain how we can replicate the problem. We cannot help you if you are just throwing pieces at us and we have to figure out first what do you actually mean. – Felix Kling Oct 13 '12 at 17:10
0

use

$.unbind( eventType, false )
Manjunath Manoharan
  • 4,567
  • 6
  • 28
  • 43
0

I think that the:

$("input").trigger('blur');

or:

$("input").blur();

is the one that you are looking for.

John Skoumbourdis
  • 3,041
  • 28
  • 34