<div class="wrap">
<div class="conte">
コンテナコンテナコンテナコンテナ
</div>
</div>
<form id="radio_ex" action="./form.php">
<label><input type="radio" name="plusone" value="aaa">100%</label>
<label><input type="radio" name="plusone" value="bbb" checked>auto</label>
</form>
.wrap{
width:250px;
height:100px;
border:5px solid red;
margin:0 auto;
}
.conte{
margin:0 10px;
border-left:10px solid skyblue;
border-right:10px solid skyblue;
background-color:blue;
color:#fff;
width:auto;
}
.conte.sp{
width:100%;
}
label{
cursor:pointer;
}
let myradio = document.querySelector("form");
let myelm = document.querySelector(".conte");
myradio.addEventListener('change', (event) => {
let radioNodeList = myradio.plusone ;
let a = radioNodeList.value ;
if (a === "aaa"){
console.log("aaaa");
myelm.classList.add("sp");
}else{
myelm.classList.remove("sp");
}
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.