• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Obtain a reference to the tag in its onclick event

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

My problem is as below:
Only the expanded or collapsed view can be shown at a time and their display is alternated on each mouse click (eg. if Collapsed view is being shown currently, on clicking the div tag it should be hidden and Expanded view should be shown and vice versa). My problem is the page can have multiple blocks of div tags of the same style and they can't/don't have unique id/name.
My question is:
Can I obtain a reference to the main div tag in its onclick event without using its name/id, so that i can use its sibling/child property to access the div tags under it.
Or suggest me if there is some other way to doing it.

Thanks in advance!
[ July 29, 2008: Message edited by: Bear Bibeault ]
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The element that initiated the event is available in the event instance. How this construct is obtained and which property contains the reference differs between standards-compliant browsers and standard-breaking Internet Explorer.

As with Ajax, I always recommend that you employ one of the popular JavaScript libraries to handle all the browser difference with event handling. Either of jQuery or Prototype has a good event-handling system, though jQuery hides more of the browser difference for you.

If you want to go it alone (not recommended), you'll need to account for the following major differences:
  • Standard browsers pass the event instance as a parameter to the handler, while IE tacks it onto the window
  • In the event instance, standard browsers use the target property to store the target reference, while IE uses srcElement
  •  
    sri pathi
    Greenhorn
    Posts: 28
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Originally posted by Bear Bibeault:
    The element that initiated the event is available in the event instance. How this construct is obtained and which property contains the reference differs between standards-compliant browsers and standard-breaking Internet Explorer.

    As with Ajax, I always recommend that you employ one of the popular JavaScript libraries to handle all the browser difference with event handling. Either of jQuery or Prototype has a good event-handling system, though jQuery hides more of the browser difference for you.

    If you want to go it alone (not recommended), you'll need to account for the following major differences:

  • Standard browsers pass the event instance as a parameter to the handler, while IE tacks it onto the window
  • In the event instance, standard browsers use the target property to store the target reference, while IE uses srcElement

  • Thanks a bunch! It worked!!
    reply
      Bookmark Topic Watch Topic
    • New Topic