Home > Article > Web Front-end > How to set height to div in javascript
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.
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
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
3. After running, we see that the heights of the two divs are the same. Next, we use js to modify the height
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
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
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.
7. Then we get the id attribute of div1 in the js file and use obj .style.cssTest to modify the embedded css
8. Then after running the project, the result is the same twice. The height of the div has changed
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!