|
|||||||
| JavaScript JavaScript (not Java) Discussion and technical support, including AJAX and frameworks (JQuery, MooTools, Prototype...) |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Detirmining if an element has focus
Hi, I was wondering if there way a way to detirmine if an element has focus or not? I want to use it in an if statement, for example:
if (elem.isFocused()) { } does anyone know how to do this? Thanks! |
|
#2
|
||||
|
||||
|
Something to play with
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html dir="ltr" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta http-equiv="content-style-type" content="text/css">
<meta http-equiv="content-script-type" content="text/javascript">
<title></title>
<style type="text/css">
body {
margin:5px;
background:#ffffff;
color:#000000;
}
</style>
<script type="text/javascript">
onload=function(){
var elem=document.getElementById("myInputField")
elem.isFocused=false;
elem.onfocus=function(){this.isFocused=true}
elem.onblur=function(){this.isFocused=false}
setInterval(
function(){
var elem=document.getElementById("myInputField")
elem.value="elem.isFocused="+elem.isFocused
}
,100
)
}
</script>
</head>
<body>
<div>
<input type="text" id="myInputField" value="" readonly="readonly">
</div>
</body>
</html>
__________________
Ultimater XMLHttpRequest: Specification | xmlhttp object | open and onreadystatechange order | String.prototype.toXMLDocument | Sarissa | Prototype | Dojo Broadening one's horizons: 24ways.org Note I have a bad habit of editing my posts hours at a time and hours later. |
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|