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 show different logo on different pages in wordpress theme?

      How to modify CSS or JS file from “materialize:materialize” package in Meteor

      How to select a non unique element through CSS

      CSS - 2 divs side-by-side, one floated - how do I make the other fit next to it without overlapping?

      How to include the PHP file that is outside the folder where main PHP file exists?

      how to do css changes only to links that are in side specific div without defining classes to a elements

      How to detect and deliver separate CSS files for mobile devices?

      How to style this value with jQuery

      How to render a hierarchy tree in HTML5/CSS?

      Bootstrap CSS - How to get control label with inline radios below it

      how to go bottom of a website like back to top using javascript?

      How to make this styling with css

      How to position an inner - inner tag at different position?

      How to change ListView cell's text color in JavaFX using css

      HTML layout with vertical divider and menu between sections - how?

      How to override default CSS in cakePHP 1.3?

      How do I add a hover to this css class for a tr?

      How to make 2 divs on 1 side (up&down)

      How do I make my footer sit at the bottom of my content?

      How to make slide down menu to slide up?

      how to combine multiple css class selectors for jquery buttonset?

      CSS how to create unveilable footer

      How to scale div from jquery css

      How to generate code for cross browser compatibility css in sublime or atom

      How to fix width of DIV that contains floated elements?

      HTML/CSS: how to position forms? [closed]

      How to adjust the width of a DIV per height using CSS

      How do you make linked text act as if it is normal text?

      How to change the width of bootstrap popover

      How to add padding space in /div container via CSS?