Search code examples
overlayjqueryjquery-tools

binding keypress not working - jquery tools overlay


I can't bind keypress for a div that I applied overlay to. Bellow is the code.

<div> 
    Content  <a href="#" id="load">Load overlay</a>
</div>

<div id="overlayDiv" class="overlay">
    <div id="someInnerDiv">
         Text 

    </div>
</div>

<script type="text/javascript> 
    function LoadOverlay()
    {
        $('#overlayDiv').overlay();
        $('#someInnerDiv').keypress(function() { alert (' key was pressed' ); });
        $('#someInnerDiv').focus();
    }
    $("#load").click(LoadOverlay);​
</script>

Alert is not showing up. Here is the code on jsfiddle: http://jsfiddle.net/JEmgg/4/

I am guessing that it's the overlay that catches the event, but I can't figure it out.


Solution

  • The problem is that you can't insert text without a textarea, an input type text or other input element. try this code and it works: DEMO

    <div id="overlayDiv" class="overlay">
        <div id="someInnerDiv">
             Text
            <input type="text" name="test" id="test"/>
        </div>
    </div>