Home>Article>Web Front-end> How to set css height in js

How to set css height in js

藏色散人
藏色散人 Original
2021-05-14 10:42:13 3370browse

How to set css height in js: 1. Modify the height of the div by modifying the style value of the div in the html file through js; 2. Use js to modify the height value of the div in the CSS file.

How to set css height in js

The operating environment of this article: Windows7 system, javascript1.8.5&&HTML5&&CSS3 version, Dell G3 computer.

How to set the height of div in js?

First open the editing tool we tested. I am using Eclipse here

We create a new test project and then Create a new index.html, basic.js and basic.css file

How to set css height in js

The first method is to modify the style value of the div in the html file using js to modify the height of the div HTML The file code in the file is as shown

How to set css height in js

After running, we see that the height of the two divs is the same. Next, we use js to modify the height

How to set css height in js

At this time we type the code in js to get the id of div1, use the style attribute corresponding to the css attribute and then set the height as shown in the picture

How to set css height in js

The second method is to use js to modify the height value of the div in the CSS file. The code in the HTML file is as shown in the figure

How to set css height in js

The code in the style sheet css file is as follows As shown in the picture, after running the project, you will see that the heights of the two divs are the same. I will not test it here

How to set css height in js

Then we get the id attribute of div1 in the js file Then use obj.style.cssTest to modify the embedded css

How to set css height in js

Then after running the project, the result is the same twice. The height of the div has changed

How to set css height in js

Recommended study: "css video tutorial"

The above is the detailed content of How to set css height in js. 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