Connecting Tech Pros Worldwide Forums | Help | Site Map

OnClick in Div only works when user clicks text

Daniel Beardsley
Guest
 
Posts: n/a
#1: Mar 31 '06
I have a div with some text in it and an onclick event. The onclick
event only seems to fire when the user clicks the text.. not if they
click the blank part of the div. This is in IE 6.

The event is assigned in my JS.

What gives?


stannyc@gmail.com
Guest
 
Posts: n/a
#2: Apr 1 '06

re: OnClick in Div only works when user clicks text


Daniel,

I suggest that you post a small sample HTML file. I'd like to know
what's in the "blank part of the div" -- do you mean nonbreaking
spaces, ASCII codes, what? Once I see a sample, I should be able to
help you.

Stan Scott
New York City

Daniel Beardsley
Guest
 
Posts: n/a
#3: Apr 2 '06

re: OnClick in Div only works when user clicks text


Here is the HTML I'm using. It's pretty simple, clicking anywhere in
the "Search" div should do an alert('hi') but it only works when I
click on the text.

I have IE 6.0.2900


<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html>
<head>
<title>Untitled</title>
<style type="text/css">
<!--
div
{
margin: 5px;
}

..c1
{
clear:both;
}

..c2
{
float:left;
margin:10px;
}

..pane
{
overflow:hidden;
display:none;
}

#pane-left
{
width:300px;
}

#pane-right
{
width:800px;
}

..sec-head
{
background-color: #FFEADA;
border-top: 1px solid #999999;
}

-->
</style>
</head>
<body>
<div class="banner"><h1>Testing</h1></div>
<div class="c1" style="overflow:auto;">
<div class="c2" id="pane-left">
<div class="sec-head" id="searchhead"
onclick="alert('hi');">Search</div>
<div class="pane" id="searchpane"><img alt="i"
src="testlong.jpg"/></div>
<div class="sec-head" id="mytrailshead" >My Stuff</div>
<div class="pane" id="mypane"><img alt="i"
src="testlong.jpg"/></div>
<div class="sec-head" id="edithead">Editing</div>
<div class="pane" id="editpane"><img alt="i"
src="testlong.jpg"/></div>

</div>
<div class="c2" id="pane-right">
<div class="sec-head" id="mainpane">
<span>Stuff</span>
<span style="text-align:right; width:50%;"><a
id="link-hide">Hide</a></span>
</div>
<div class="c1"></div>
<div class="sec-head" id="infopane">Info</div>
<div class="c1"></div>
</div>
</div>
</body>
</html>


stannyc@gmail.com wrote:[color=blue]
> Daniel,
>
> I suggest that you post a small sample HTML file. I'd like to know
> what's in the "blank part of the div" -- do you mean nonbreaking
> spaces, ASCII codes, what? Once I see a sample, I should be able to
> help you.
>
> Stan Scott
> New York City[/color]

Closed Thread