0

I'm essentially making jepoardy and trying to store a temporary variable using the inner, however when the user clicks the button, it takes them to the next page before the onclick function can be called. I've tried putting the onclick function inside the tag, but it still doesn't work.

<a href="Easy.html"><button type="button"  onclick="categoryOnClick() "id="answer0" class="buttonquestion">200</button></a>  

var tempscore = 0;
var currentscore = 0;

function categoryOnClick(){
    tempscore = parseInt(this.innerHTML);
}
MehLdy
  • 57
  • 1
  • 7

1 Answers1

0

You may need to pass the context this , otherwise inside the function this will refer to the window

Also a button inside an anchor tag is not a valid HTML.button cannot be nested inside a tag.Check here for more information

var tempscore = 0;
var currentscore = 0;

function categoryOnClick(elem) {
  console.log(elem)
  tempscore = parseInt(elem.innerHTML);
  console.log(tempscore)
}
<a href="Easy.html">
  <button type="button" onclick="categoryOnClick(this) " id="answer0" class="buttonquestion">200</button>
</a>
brk
  • 48,835
  • 10
  • 56
  • 78