How do I know which div was clicked?

Tags: javascript,html5,css3

Problem :

I am making a game of tic-tac-toe using HTML5, CSS and JavaScript. I have identified the winning patterns and more or less how to make it work. There is no artificial intelligence involved; it is intended to be a player-vs-player-on-the-same-computer game.

enter image description here

All I want to do is:

  • Know when a div is clicked
  • Know which div is clicked
  • Please tell me if that is possible. If yes, how. Steps appreciated, don't post complete code :)

    Solution :

    Bind an event listener to the container, then examine the target property of the event object to determine which element was clicked.

    Seriously consider replacing the <div>s with <button>s as they are designed to be interactive (so have benefits such as automatically appearing in the focus order).

      CSS Howto..

      How to remove a specific (bottom) border from p:row in p:panelGrid?

      CSS HTML How to align image within div to bottom right

      How to write CSS in Vaadin 6?

      How to change the CSS of Background Element?

      How can I invoke an “AktionLink” in an “onClick” event in a “div”?

      How would I go about applying some sort of dynamic range counter to jQuery and CSS?

      How do I organize imports in Compass/Blueprint?

      How to disable css warning “Unknown property” in Eclipse Mars?

      How to arrange elements vertically?

      How to correctly switch images with javascript?

      How to create four even and fluid css columns?

      Changing backgrounds for CSS slideshow

      How to move the POV of an image when using overflow: hidden?

      How can I make this little javascript work with 2 textarea elements without killing the CSS?

      Responsive CSS - how to 'dynamically' align div to parent width with padding/margin?

      How to make this image blur with css

      How to make the margins and border in a mobile website invisible html/css

      How to create a border with spaces in it [duplicate]

      newbie css/php question - how to get a div between a label and an input with cakephp

      Creating an animated image slider - how to animate and restrict multiple clicks?

      How to add image at right bottom div using css

      Responsive layout, how to keep text at bottom of dynamically resizing image

      How to avoid bloating pages with divs?

      how to change other element css when selected element has new class

      How to make long Bootstrap dropdown menus vertically scrollable?

      How to show sorting order if column width is smaller than caption in free jqgrid

      TD Borders from a table, not showing in IE8 [duplicate]

      How to apply row virtualization for a table / list in HTML/CSS/JS? [closed]

      How to make a site have a built in user-friendly editor?

      How can I add a custom HTML map marker to a Nokia HERE map?