var 1 = document.getElementById("1").click();
var 2 = document.getElementById("2").click();
var 3 = document.getElementById("3").click();
 if(1){
    userChoice =="1";
}else if (2){
    userChoice == "2";
}else if (3){
    userChoice == "3";
}

I'm working on code that gets user choice when the user clicks on a div.I'm attempting to 'get' the element and assign it to a variable but it returns null, couldn't find a solution in jquery either.Any suggestions??

You can create one function then for each div, attach an onclick event that sends the function a number.

For example...

 <div onclick="clicked(1)"></div>

Then the function...

 function clicked(userChoice) {
      If (userChoice == 1) {
           // some code
      } else if (userChoice == 2) {
           // some code
      }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.