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

How to set height to div in javascript

coldplay.xixi
coldplay.xixiOriginal
2021-04-08 13:38:0712697browse

How to set the height of div in javascript: first create a new project; then modify the style value of the div in the html file to modify the height of the div; and finally run the project.

How to set height to div in javascript

The operating environment of this tutorial: Windows 7 system, JavaScript version 1.8.5, DELL G3 computer.

How to set the height of div using JavaScript:

1. First, we create a new test project and then create a new index.html, basic.js and basic.css files

How to set height to div in javascript

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

How to set height to div in javascript

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

How to set height to div in javascript

4 , 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 figure

How to set height to div in javascript

5. The second method is to use js modifies 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 height to div in javascript

6. The code in the style sheet css file is as shown in the figure. Run the project After that, you will see that the height of the two divs is the same. I will not test it here.

How to set height to div in javascript

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

How to set height to div in javascript

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

How to set height to div in javascript

Related free learning recommendations: javascript video tutorial

The above is the detailed content of How to set height to div 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