Registering Onclick Anywhere in a <div>

Discussion in 'Web Design and Development' started by crees!, Jun 30, 2006.

  1. crees! macrumors 68000

    crees!

    Joined:
    Jun 14, 2003
    Location:
    MD/VA/DC
    #1
    As an example the <div> contains just text ("hello") and the div has a width of 300px and height of 100px with a solid border around it. I have a function tied to the onClick handler for the <div> but it only fires when you click on the text. I want it so you can click anywhere within the <div> for it to fire. Unforunately this is for IE5.5+ only.

    Any idea how this can be done? I tried setting display:block but that didn't help. Really, I have to be missing something here. Watch it be another "deedeedee" moment that I'm having.

    \m/
     
  2. crees! thread starter macrumors 68000

    crees!

    Joined:
    Jun 14, 2003
    Location:
    MD/VA/DC
  3. floyde macrumors 6502a

    floyde

    Joined:
    Apr 7, 2005
    Location:
    Monterrey, México
    #3
    Hmmm... I think I did this once... It worked naturally on Firefox, Safari, etc. but IE was being nasty about it (as usual ;) ). I think you could make it work on IE by using a transparent background image on the div. All you need is a 1px X 1px transparent gif and set background-repeat to repeat.
     
  4. crees! thread starter macrumors 68000

    crees!

    Joined:
    Jun 14, 2003
    Location:
    MD/VA/DC
    #4
    You know.. that's so weird because I JUST figured this out. My thinking was "don't make me stretch spacer images over each div I need this on and tie an onclick to them." So I tried it with 1 of the div's and it worked. So I put them on a couple more but noticed some of the div that didn't have the spacer yet had their clicks register!!! I have a bunch of nested div's and it seems I only need the spacer in 1 and it'll work for all others in that container. Damn IE, ruining my day.
     

Share This Page