Home >Web Front-end >JS Tutorial >How to set high in javascript

How to set high in javascript

藏色散人
藏色散人Original
2021-06-30 10:51:333351browse

How to set the height in javascript: first get the element with the specified id; then get the current height of "p_count"; finally pass "$("p_count").style.height="900" "px";" Just set a fixed height.

How to set high in javascript

The operating environment of this article: windows7 system, javascript version 1.8.5, Dell G3 computer.

How to set javascript to high?

js sets the height of the specified div

The code is as follows:

<script type="text/javascript">
function $(id){ //获指定id的element,方法形如jQuery
return document.getElementById(id);
}
function getHeight(){
var a=$("p_count").offsetHeight; //得到p_count目前的高
if(a>1000)
{
//alert(a);
}
else{
$("p_count").style.height="900"+"px"; //设定定高
}
}
window.οnlοad=function(){
getHeight();
}
</script>
<div id="p_count" style="border:1px solid #ccc">lalala</div>

[Related recommendations: javascript advanced tutorial]

The above is the detailed content of How to set high in javascript. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn