jquery height() method


  Translation results:

height

English [haɪt] American [haɪt]

n. Height; height, altitude; highland; extreme, vertex

jquery height() methodsyntax

Function: height() method returns or sets the height of the matching element.

Return height: Return the height of the first matching element. If no arguments are set for this method, the height of the matching element in pixels is returned.

Syntax: $(selector).height()

Set the height: Set the height of all matching elements.

Syntax: $(selector).height(length)

##Parameters:

ParameterDescriptionlength Optional. Specifies the height of the element. If no length unit is specified, the default px unit is used.

#Use a function to set the height: Use a function to set the height of all matching elements.

Syntax: $(selector).height(function(index,oldheight))

Parameters:

ParametersDescriptionfunction(index,oldheight)Specifies to return the new height of the selected element function. index Optional. Accepts the index position of the selector oldvalue Optional. Accepts the current value of the selector.

jquery height() methodexample

<html>
<head>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $(".btn1").click(function(){
    $("p").height(50);
  });
});
</script>
</head>
<body>
<p style="background-color:yellow">This is a paragraph.</p>
<button class="btn1">改变高度</button>
</body>
</html>
Run instance »

Click the "Run instance" button to view the online instance

Popular Recommendations