[jQuery] Keypress on a div
Hi all. I'm newbie about jquery so sorry for the stupid question.
I have this code:
<html>
<head>
<script type="text/javascript" src="jquery-1.1.2.js">
<script>
</script>
</head>
<body>
<div id="contenitore" class="contenitoreC" style="border: 3px black solid;float:left;" >
<div id="sotto1" class="interno" style="border:2px red solid; width:200px;height:200px; float:left;"></div>
<div id="sotto2" class="interno" style="border:2px green solid; width:200px;height:200px; float:left;"></div>
<div id="sotto3" class="interno" style="border:2px blue solid; width:200px;height:200px; float:left;"></div>
<div id="sotto4" class="interno" style="border:2px yellow solid; width:200px;height:200px; float:left;"></div>
<div id="sotto5" class="interno" style="border:2px orange solid; width:200px;height:200px;float:left;"></div>
</div>
<script type="text/javascript">
var _mousedown = -1;
var last = -1;
var lastlast = -1;
var now = -1;
var first = -1;
var shift = -1;
$(document).ready( function() {
$('div.interno').hover(
//IN
function() {
if (_mousedown == 0) {
$(this).css('background','#999999');
$(this).text('ippo');
{
lastlast = last;
$('#divlastlast').text(lastlast)
last = now;
$('#divlast').text(last)
now = $(this).attr('id');
$('#divnow').text(now)
if (now == lastlast || now == first) {
$('#'+last).css('background','white');
}
}
}
}
,
//out Nulla da fare qui.
function () {}
);
$('div.interno').mousedown( function () {
$('
div.interno').css('background','white');
_mousedown = 0;
$(this).css('background','#999999')
now = $(this).attr('id');
first = $(this).attr('id');
last = -1;
lastlast = -1;
$('#divfirst').text(now);
$('#divnow').text(now);
//alert($(this).attr('id'));
});
//IF I uncomment this line keypress works
//$(document).keypress(function(e) {alert(e.charCode); $('#debug').text(' ');for (i in e) {$('#debug').append(' -- ' + i);}});
$('div.interno').mouseup( function() {_mousedown = -1});
$('#contenitore').keypress(function (e) {
alert('dentro');
});
});
</script>
<br clear="all">
first:<div id="divfirst"></div>
now:<div id="divnow"></div>
last: <div id="divlast"></div>
lastlast:<div id="divlastlast"></div>
debug:<div id="debug"></div>
</body>
</html>
I want to realize this: when the user click into one of #sotto[1-5] div and the "CTRL KEY" is pressed the div change his background color (In the code I have set the click way only). But I have a problem about how to intercept the "CTRL KEY". I have thinked that
$('#contenitore').keydown() is "my friend", but it does not work. I have tried the line that you see into the code, but I don't know why it does not work with all key. Keypress works only on $(document).
Where is my error ?
Tnx.
M.
--
Michel 'ZioBudda' Morelli <a href="mailto:michel@ziobudda.net">michel@ziobudda.net</a>
Consulenza sistemistica in ambito OpenSource.
Sviluppo applicazioni web dinamiche (LAMP+Ajax)
Telefono: +39-3939890025 -- Fax: +39-0291390660
<a href="http://www.ziobudda.net">http://www.ziobudda.net</a> ICQ: 58351764
<a href="http://www.ziobuddalabs.it">
http://www.ziobuddalabs.it</a> Skype: zio_budda
<a href="http://www.ajaxblog.it">http://www.ajaxblog.it</a> MSN: <a href="mailto:michel@ziobuddalabs.it">michel@ziobuddalabs.it
</a>