Javascript DOM CSS Style maxWidth Property get

Introduction

Return the maximum width of a <div> element:

alert(document.getElementById("myDiv").style.maxWidth);

View in separate window

<!DOCTYPE html>
<html>
<body>

<div style="background:red;max-width:60px;" id="myDiv">This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text.</div><br>

<button type="button" onclick="myFunction()">Return max width of div</button>

<p id="demo"></p>


<script>
function myFunction() {/* ww w . ja  v  a2  s. c o  m*/
  document.getElementById("demo").innerHTML = document.getElementById("myDiv").style.maxWidth;
}
</script>

</body>
</html>



PreviousNext

Related