How do I set a width to a element with a var?
I have this code:
$(".menu_list_item").css({
width: width + "%"
});
But this does not seem to work.
Any help would be appreciated.
How do I set a width to a element with a var?
I have this code:
$(".menu_list_item").css({
width: width + "%"
});
But this does not seem to work.
Any help would be appreciated.
This is an example.
$(document).ready(function() {
var duzina = "50%"
$(".box").css({
width: duzina
});
});
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Naslov</title>
<style>
* {
margin: 0px;
height: 0px;
}
html, body, .container {
width: 100%;
height: 100%;
background-color: red;
display: flex;
justify-content: center;
align-items: center;
}
.box {
height: 250px;
background-color: orange;
}
</style>
<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script>
$(document).ready(function() {
var duzina = "25%"
$(".box").css({
width: duzina
});
});
</script>
</head>
<body>
<div class="container">
<div class="box">
</div>
</div>
</body>
</html>