keyboard shortcuts to access divs

  • Thread starter samuelberthelot
  • Start date
S

samuelberthelot

Hi,
I have a number of divs on my page, which are generated dynamically
from records in a database. Each div is collapsible (display:none or
display:block) when clicking on the header (a hyperlink).

I've got two groups (diffent color) of divs. I would like that when the
user presses ctrl-1, the first div of the first group is given the
focus, and when he presses ctrl-2, the first div of the second group is
given the focus. How can I do that ?

Thanks
 
M

Marc

Hi,
I have a number of divs on my page, which are generated dynamically
from records in a database. Each div is collapsible (display:none or
display:block) when clicking on the header (a hyperlink).

I've got two groups (diffent color) of divs. I would like that when the
user presses ctrl-1, the first div of the first group is given the
focus, and when he presses ctrl-2, the first div of the second group is
given the focus. How can I do that ?

Thanks

perhaps something 'hacky' like this:

(notice, Ctrl key does something unexpected in FF, I used the Alt key
and only tested this in IE & FF)


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css"> <!--
..focus{background-color: #fafad2}
..focusout{background-color: #ffffff}
--></style>
<script language="javascript" type="text/javascript">
//<![CDATA[
<!--
document.onkeydown = function(e){
var evt = window.event ? event : e;
var j = document.getElementsByTagName("DIV");
for (var i=0; i < j.length; i++){
if (j.className == "" || j.className == "focus"){
j.className = "focusout";
}
}
if (evt.altKey){
if (evt.keyCode==49){
document.getElementById("div1").className = "focus";
}else if (evt.keyCode==50){
document.getElementById("div2").className = "focus";
}else if (evt.keyCode==51){
document.getElementById("div3").className = "focus";
}
}
}
//-->
//]]>
</script>
</head>
<body>

<div id="div1" class="">div1</div>

<div id="div2" class="">div2</div>

<div id="div3" class="">div3</div>

</body>
</html>
 
S

samuelberthelot

Thanks for your help, I'll give it a go.
Marc said:
Hi,
I have a number of divs on my page, which are generated dynamically
from records in a database. Each div is collapsible (display:none or
display:block) when clicking on the header (a hyperlink).

I've got two groups (diffent color) of divs. I would like that when the
user presses ctrl-1, the first div of the first group is given the
focus, and when he presses ctrl-2, the first div of the second group is
given the focus. How can I do that ?

Thanks

perhaps something 'hacky' like this:

(notice, Ctrl key does something unexpected in FF, I used the Alt key
and only tested this in IE & FF)


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css"> <!--
.focus{background-color: #fafad2}
.focusout{background-color: #ffffff}
--></style>
<script language="javascript" type="text/javascript">
//<![CDATA[
<!--
document.onkeydown = function(e){
var evt = window.event ? event : e;
var j = document.getElementsByTagName("DIV");
for (var i=0; i < j.length; i++){
if (j.className == "" || j.className == "focus"){
j.className = "focusout";
}
}
if (evt.altKey){
if (evt.keyCode==49){
document.getElementById("div1").className = "focus";
}else if (evt.keyCode==50){
document.getElementById("div2").className = "focus";
}else if (evt.keyCode==51){
document.getElementById("div3").className = "focus";
}
}
}
//-->
//]]>
</script>
</head>
<body>

<div id="div1" class="">div1</div>

<div id="div2" class="">div2</div>

<div id="div3" class="">div3</div>

</body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top