Home > Web Front-end > JS Tutorial > body text

How to set high in javascript

藏色散人
Release: 2021-06-30 10:51:33
Original
3334 people have browsed it

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>
Copy after login

[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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template