ie7 onclick on a div

J

josh

Hi,
if I have a div and than I put on it an handler like that:


#div3 {
position:absolute;
left:18px;
top:11px;
width:768px;
height:472px;
border: thin solid #99FFCC;
}

<div class="div3" onclick="foo()">
</div>

than the event is not fired!

any bug? in firefox the event fire!

Thanks
 
M

Martin Honnen

josh said:
if I have a div and than I put on it an handler like that:


#div3 {
position:absolute;
left:18px;
top:11px;
width:768px;
height:472px;
border: thin solid #99FFCC;
}

<div class="div3" onclick="foo()">
</div>

Not sure what the CSS has to do with it but the selector #div3 does not
apply to that div element, you either need to change the markup to
<div id="div3" ...>
or the CSS to
.div3 { ... }
 
J

josh

Not sure what the CSS has to do with it but the selector #div3 does not
apply to that div element, you either need to change the markup to
<div id="div3" ...>
or the CSS to
.div3 { ... }

yes the selector is wrong but the code is not relative to it.
so what's the problem? may be if a div does not contain any other
element it does not
react to an event?
thanks
 
T

The Magpie

josh said:
yes the selector is wrong but the code is not relative to it.
so what's the problem? may be if a div does not contain any other
element it does not react to an event?
Josh, the point Martin was making is that the CSS code was wrong - as
you have agreed - *and* that you have not shown the code for the click
function (the "event").
 
J

josh

Josh, the point Martin was making is that the CSS code was wrong - as
you have agreed - *and* that you have not shown the code for the click
function (the "event").

ok I post you the correct code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Esempio d'uso della libreria</title>
<style type="text/css">

..div3
{
position:absolute;
left:18px;
top:11px;
width:768px;
height:472px;
border: thin solid #99FFCC;
}

</style>

</head>
<body>
<div class="div3" onclick="alert(4)"></div>
</body>
</html>

however it seems as ie does not react when a div does not contain any
child.
In fact if I insert some text in it then the event is triggered but
only on that
text. But I don't want that I want that the div trigger the event on
all is space.
 
R

Robin

josh said:
ok I post you the correct code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Esempio d'uso della libreria</title>
<style type="text/css">

.div3
{
position:absolute;
left:18px;
top:11px;
width:768px;
height:472px;
border: thin solid #99FFCC;
}

</style>

</head>
<body>
<div class="div3" onclick="alert(4)"></div>
</body>
</html>

however it seems as ie does not react when a div does not contain any
child.
In fact if I insert some text in it then the event is triggered but
only on that
text. But I don't want that I want that the div trigger the event on
all is space.

Does adding a "&nbsp;" into the div help?

Robin
 
B

Bart Van der Donck

josh said:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Esempio d'uso della libreria</title>
<style type="text/css">
.div3
{
position:absolute;
left:18px;
top:11px;
width:768px;
height:472px;
border: thin solid #99FFCC;
}
</style>
</head>
<body>
<div class="div3" onclick="alert(4)"></div>
</body>
</html>

however it seems as ie does not react when a div does not contain
any child.
In fact if I insert some text in it then the event is triggered but
only on that text. But I don't want that I want that the div trigger
the event on all is space

You should set MSIE6+ in HTML4 standards-compliant mode in stead of
XHTML 1.0:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

or even

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

More info:
http://msdn2.microsoft.com/en-us/library/ms535242.aspx

Hope this helps,
 
S

Steve Swift

however it seems as ie does not react when a div does not contain any
child.
In fact if I insert some text in it then the event is triggered but
only on that
text. But I don't want that I want that the div trigger the event on
all is space.

I think that a DIV that contains nothing (<DIV></DIV> with nothing
between) doesn't exist as far as IE is concerned.

I think that adding as little as a space fixes this (<DIV> </DIV>) but
that might ruin your formatting. Try it first though, I'm a DIV virgin.
 

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

Forum statistics

Threads
474,154
Messages
2,570,870
Members
47,400
Latest member
FloridaFvt

Latest Threads

Top