Link to home
Start Free TrialLog in
Avatar of jxharding
jxharding

asked on

JQuery - make a popup that disappears (like datepicker) when clicking outside popup

The below code works in a jsfiddle in Chrome but not in IE7/8/9.



What is meant to happen is:
 1.
click on "onetxt" then the red block appears.

2.
the red block must only hide if you click on anything except "Input1" , "redDiv" or "onetxt"

 
What happens is if you click on the redDiv then it hides -- it looks like its because the red div is not getting focused in time.

The effect required is that of the jquery datpicker - if you click outside of the div, the div hides. If you click on the div - the div stays visible.

Can you please help..

thanks


<div id="myarea"></div>



    <br /><br />
    <br /><br />
    <br /><br />
    <br /><br />
    <br /><br />
    <br /><br />
    <br /><br />
    <br /><br />
    <br /><br />
    <br /><br />


    <input type="text" id="test"  />

Open in new window


       $(document).ready(function () {
            var hider = null;
            var onetxt = $('<input type="text" />');
            var Input1 = $('<input type="text" />');
            var redDiv = $('<div>', {
                tabindex: "5",
                style: "width:200px;height:200px;background:red; ",
                text: 'test',
                html: "<br /><br />"
            }).append(Input1);


            redDiv.hide();

            onetxt.focus(function () { redDiv.show();});
            Input1.focus(function () { redDiv.show();});
            redDiv.focus(function () { redDiv.show()});

            onetxt.blur(function () { redDiv.hide();});
            Input1.blur(function () { redDiv.hide();});
            redDiv.blur(function () { redDiv.hide() });

            $('#myarea').after(onetxt, redDiv);
        });

Open in new window

Avatar of leakim971
leakim971
Flag of Guadeloupe image

comment lines 19 and 21 : http://jsfiddle.net/Fu5qm/5/

            //onetxt.blur(function () { redDiv.hide();});
            Input1.blur(function () { redDiv.hide();});
            //redDiv.blur(function () { redDiv.hide() });

Open in new window

Avatar of jxharding
jxharding

ASKER

Hi leakim971, I still have the same effect. If you click in the top textbox or on the red div, and then outside of it, the popup still shows (I'm trying to make it disappear - like the datepicker control).  Currently, only if you click on the textbox inside the red div, and then outside does it disappear.
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks, I'm giving up on this one unfortunately. Chrome works well, but not FireFox or IE unfortunately. Thanks for your time and expertise.