0

By select, I mean select()

My code is this:

    $('.show-embed-link').unbind('click');
    $(".show-embed-link").click(function(e){
        var id = $(this).attr("rel");
        e.preventDefault();
        showEmbed(id);
        setTimeout(function() {
            $("#general_message").focus();
        }, 100);
    });

.show-embed-link is not dynamic element. It is a <a> element.

showEmbed will generate a dynamic element.

function showEmbed(id) {
        var message = '<iframe width="1000" height="800" src="//storyzer.com/stories/'+id+'" frameborder="0" allowfullscreen></iframe>';
        message = HtmlEncode(message);
        showOverlayForGeneral(message, "Embed work", {'spinner': false, 'extraheight': 90, 'showclose': true});
 }

showOverlayForGeneral is responsible for generating the dynamic element with the message.

function showOverlayForGeneral(message, title, options) {
    options = (typeof options === "undefined") ? {} : options;
    var defaultOptions = {
        "message": "",
        "extraheight": 150,
        "spinner": true,
        "showclose": false
    };

       // code removed because not relevant to this situation...

    $('#general_message').unbind('focus');
    $('#general_message').focus(function () {
        $('#general_message').select().mouseup(function (e) {
            e.preventDefault();
            $(this).unbind("mouseup");
        });
    });
}

The focus code is taken from https://stackoverflow.com/a/3380493

Currently, my div html is not selected. How can I tell if the select event is happening?

Community
  • 1
  • 1
Kim Stacks
  • 10,202
  • 35
  • 151
  • 282

1 Answers1

0

try this one

$(document).ready(function(){
     $('#general_message').unbind('focus');
        $('#general_message').focus(function () {
            $('#general_message').select().click(function (e) {
                e.preventDefault();
                $(this).unbind("click");
            });
        });
})
Sumit Pathak
  • 671
  • 1
  • 6
  • 25
  • Why change the mouseup to click? – Kim Stacks Mar 21 '14 at 04:58
  • i think you want to focus the div part, so when you click that div then it should be focusing on your div so i just replace the mouseup to click function.@KimStacks – Sumit Pathak Mar 21 '14 at 05:00
  • I don't want to click on the div. I want it to focus via javascript. See my first code block. I used .focus() – Kim Stacks Mar 21 '14 at 05:07
  • the focus function is inside the div click function so how the focus function work without clicking that div.? i edited my answer see that. @KimStacks – Sumit Pathak Mar 21 '14 at 05:20