jquery - How do I make a JAVASCRIPT variable equal to an HTML attribute? -


i trying have number displayed starts @ 0 , goes randomly every time press button. need variable equal current number(which stored within h1 tag). how do that? when try check if worked alerting page, [object htmlheadingelement] here javascript, css, , html code, respectively:

function myrandom() {    var headnumber = document.getelementbyid('headnum');    alert(headnumber)      //the alert check if '0' comes up'  }
     h1 {    text-align: center;    font-size: 30px;    color: blue;    font-family: verdana;  }  button {    margin-left: 640px;    border: solid blue 5px;    font-size: 14px;    font-family: verdana;    font-weight: bold;    background-color: cyan;    border-radius: 6px;  }
<h1 id='headnum'>3</h1>  <button onclick="myrandom()">button</button>

you html content using innerhtml. see below,

function myrandom() {    var headnumber = document.getelementbyid('headnum').innerhtml;    alert(headnumber)      //the alert check if '0' comes up'  }
h1 {    text-align: center;    font-size: 30px;    color: blue;    font-family: verdana;  }  button {    margin-left: 640px;    border: solid blue 5px;    font-size: 14px;    font-family: verdana;    font-weight: bold;    background-color: cyan;    border-radius: 6px;  }
<h1 id='headnum'>3</h1>  <button onclick="myrandom()">button</button>


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -