To get and set the width of an html element, width()
method can be used. If we pass parameter, it sets the width of the element otherwise it simply gives the width of the element.
<script>
$("h1").css("background", "#c0c0c0").width("200px");
</script>
Above code snippet will first change the background color and set the width of the “h1” tag to 200px.
<script>
alert($("h1").width());
</script>
Above code snippet will show the width of “h1” element in JavaScript alert.
Views: 5060 | Post Order: 52