Jim Jim - 3 months ago 12
Javascript Question

Change div height on button click

What I do wrong ? Why div height didn't change ? Thanks in advance...

<html>
<head>
</head>

<body >
<button type="button" onClick = "document.getElementById('chartdiv').style.height = 200px">Click Me!</button>
<div id="chartdiv" style="width: 100%; height: 50px; background-color:#E8EDF2"></div>
</body>
</html>

Answer

Just a silly mistake use quote('') in '200px'

 <html>
  <head>    
  </head>

<body >
    <button type="button" onClick = "document.getElementById('chartdiv').style.height = '200px';">Click Me!</button>
    <div id="chartdiv" style="width: 100%; height: 50px; background-color:#E8EDF2"></div>
</body>

Comments