Hi I am trying to run this code that finds the width of div which is inside another div. but it is not running properly. How to do this?
i want the width of div mitem1
Code:
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
div#mydiv {
width: 100px;
height: 100px;
background-color: red;
}
</style>
<script language="JavaScript">
$('.menubar').each(function(menu){
var len = $(this).find('.mitem').text().length;
alert(len);
});
</script>
</head>
<body>
<div class="menubar">
<table border="1"><tr>
<td><div class="mitem1">Home</div></td>
<td><div class="mitem1">Communities<ul><li>item1</li><li>item2</li><li>item3</li><li>item4</li><li>item5</li></div></td>
<td><div class="mitem1">Project Gallery</div></td>
<td><div class="mitem1">For Our Customer</div></td>
<td><div class="mitem1">Our Services</div></td>
</tr></table>
</div>
</body>
</html>
$('.menubar .mitem1').each(function() {
alert($(this).width());
});
If you want to get the width, including the padding and border (and margin, optional), use outerWidth()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With