Reputation: 568
I want to access class"pdocCover" for set width and height of body by javaScript . How should I do?.
<?xml version="1.0" encoding="utf-8"?>
<!-- Generated by PubliForge, $Date: 2012/02/03 12:17:54 $ -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta http-equiv="Content-Language" content="en"/>
<title>Couverture</title>
<link rel="StyleSheet" href="Css/reset.css" type="text/css"/>
<link rel="StyleSheet" href="Css/publidoc.css" type="text/css"/>
<link rel="StyleSheet" href="Css/main.css" type="text/css"/>
</head>
<body class="pdocCover">
<div>
<img src="Images/9782919504060.png" alt="Couverture"/>
</div>
</body>
</html>
Upvotes: 1
Views: 13843
Reputation: 132
document.getElementByClassName("Classname")
should return array of object who have class "classname". choose your one by selecting the index: [0] the first element, [1] the second etc.
Upvotes: 0
Reputation: 1535
To achieve what you specifically described:
document.getElementsByClassName('pdocCover')[0].width = '100px'
... but that probably isn't what you want. For one you can access the body
more quickly and clearly by doing:
document.getElementsByTagName('body')[0]
and this will not change the width or height of the window itself if that is what you are attempting to do. Unless you create a new window with window.open
you do not have control of the window size.
Upvotes: 1
Reputation: 2051
By using jQuery
$(".pdocCover").css("height","500px");
$(".pdocCover").css("width","500px");
By using JavaScript
document.getElementsByClassName('pdocCover').style.height="500px;"
document.getElementsByClassName('pdocCover').style.width="500px;"
Upvotes: 1