How can I change the CSS properties (width by height) of a div element via JQuery?
Why doesn't this create a vertical width of 5 pixels wide on the travel side of the window?
<html>
<head runat="server">
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#scrollBar").css({
height: $(window).height,
width: 5,
position: "absolute",
top: 0,
left: $(window).width - 5,
margin: 0
});
});
</script>
</head>
<body>
<div id="scrollBar" style="background-color: Red">test
</div>
</body>
</html>
source to share
Use this instead:
I found several problems:
- instead
$(window).height
, use$(window).height()
-
instead
left: $(window).width - 5
, useright: 0
$(document).ready(function() { $("#scrollBar").css({ height: $(window).height(), width: 5, position: "absolute", top: 0, right: 0, margin: 0 }); });
source to share
From reading the jQuery documentation, you can see that you need to put css properties and their values ββas string values.
$ ("# scrollBar"). css ({ 'height': $ (window) .height (), 'width': '5px', 'position': 'absolute', 'top': '0', 'left': $ (window) .width () - 5, 'margin': '0' });
http://docs.jquery.com/CSS/css#properties
I'm not sure how much you will show these calculated values.
PS: Jonatas was the correct height, and the widths are functions, not properties.
source to share
left: $(window).width - 5
You can try instead right: 0
.
EDIT: Yes, that was pretty silly. But, if I'm not mistaken, they should also be specified as in "width": "5px".
$("#scrollBar").css({
'height': $(window).height(),
'width': '5px',
'position': 'absolute',
'top': 0,
'right': 0,
'margin': 0
});
source to share