how to draw a frame around an element

M

Mel

I need to draw a red frame around the element under current pointer.

I have seen it done in debuggers, but need to have it in my
application, without the need to download and install applications.

Any help is appreciated
 
J

Janwillem Borleffs

Mel said:
I need to draw a red frame around the element under current pointer.

I have seen it done in debuggers, but need to have it in my
application, without the need to download and install applications.

Any help is appreciated

Not that hard to accomplish:

var elem, elemOriginalBorder;

function borderOn(e) {
if (!e) e = event;
e = e.target || e.srcElement;
if (e && e.style) {
elem = e;
elemOriginalBorder = e.style.border;
e.style.border = '1px solid red';
}
}

function borderOff(e) {
if (elem) {
elem.style.border = elemOriginalBorder;
}
}

document.onmouseover = borderOn;
document.onmouseout = borderOff;


JW
 
S

scripts.contact

I need to draw a red frame around the element under current pointer.

I have seen it done in debuggers, but need to have it in my
application, without the need to download and install applications.

Any help is appreciated

try:

<html>
<head>
<title>Borders</title>
<script>
var pv={e:'',s:''}
document.onmousemove=function(Event){
Event=(Event||event)
Eleme=Event.srcElement||Event.target
if(pv.e)pv.e.style.border=pv.s
pv.e=Eleme;pv.s=Eleme.style.border
Eleme.style.border="1px dashed red"
}
</script>
</head>
<body>
<div>A</div>
<p><span>B</span><b>dsf</b></p>
</body>
</html>
 
P

prince

I need to draw a red frame around the element under current pointer.

I have seen it done in debuggers, but need to have it in my
application, without the need to download and install applications.

Any help is appreciated

CSS is better than javascript for this.
for example try
-------------------------HTML CODE ---------------------
<html><head>
<style type="text/css">
.brdr:hover{border:1px solid #F00; }
</style>
</head>
<body>
<div class="brdr"> this will have a border</div>
<div> this wont</div>
</body></html>
------------------------------ End sample code -------------
HTH
Prince
 
P

prince

try:

<html>
<head>
<title>Borders</title>
<script>
var pv={e:'',s:''}
document.onmousemove=function(Event){
Event=(Event||event)
Eleme=Event.srcElement||Event.target
if(pv.e)pv.e.style.border=pv.s
pv.e=Eleme;pv.s=Eleme.style.border
Eleme.style.border="1px dashed red"
}
</script>
</head>
<body>
<div>A</div>
<p><span>B</span><b>dsf</b></p>
</body>
</html>
 
V

VK

CSS is better than javascript for this.

It is, but until IE 6 remains in a non-negligible use, :hover rule
will be limited to links only - this is the only element where IE6
supports :hover
 
M

Mel

try:

<html>
<head>
<title>Borders</title>
<script>
var pv={e:'',s:''}
document.onmousemove=function(Event){
Event=(Event||event)
Eleme=Event.srcElement||Event.target
if(pv.e)pv.e.style.border=pv.s
pv.e=Eleme;pv.s=Eleme.style.border
Eleme.style.border="1px dashed red"
}
</script>
</head>
<body>
<div>A</div>
<p><span>B</span><b>dsf</b></p>
</body>
</html>

Your code works fine except one little glitch. On mouse over does the
job of placing border, however on MousOut, My element disapears
completelty from the screen. Can't tell you why, I just copied your
code into my app without any change and that is what is happening with
form elements like text etc.

Any pointer is appreciated
 
S

scripts.contact

Your code works fine except one little glitch. On mouse over does the
job of placing border, however on MousOut, My element disapears
completelty from the screen. Can't tell you why, I just copied your
code into my app without any change and that is what is happening with
form elements like text etc.

The code works fine for me in FF2,IE6,OP9
 

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
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top