Return the maximum width of a <div> element: - Javascript CSS Style Property

Javascript examples for CSS Style Property:maxWidth

Description

Return the maximum width of a <div> element:

Demo Code

ResultView the demo 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>

<script>
function myFunction() {/*from w  w w .java2  s  .  c o m*/
    console.log(document.getElementById("myDiv").style.maxWidth);
}
</script>

</body>
</html>

Related Tutorials