I'm trying to create my own Radio Button
. I have created a Switch
prototype and I'm not able to select the :before
of the this
div.radio_button. How can I query the :before
into a variable?
HTMLDivElement.prototype.Switch = function() {
if ((this.getAttribute("class") == "radio_button")) {
var s = this.querySelector("::before"); // s being null
console.log(s);
}
};
HTMLDivElement.prototype.selected = false;
document.querySelector("div.radio_button").Switch();
div.radio_button {
height: 30px;
width: 50px;
background-color: rgb(190, 190, 190);
-webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
-moz-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
-webkit-border-radius: 25px;
-moz-border-radius: 25px;
border-radius: 25px;
position: relative;
margin: 0;
-webkit-transition: 0.5s;
transition: 0.5s;
}
div.radio_button:before {
content: '';
height: 30px;
width: 30px;
-webkit-border-radius: 50%;
-moz-border-radius: 50%;
border-radius: 50%;
-webkit-box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
-moz-box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
position: absolute;
top: 0;
left: 0;
background-color: rgb(255, 255, 255);
-webkit-transform: scale(1.1);
-moz-transform: scale(1.1);
-ms-transform: scale(1.1);
-o-transform: scale(1.1);
transform: scale(1.1);
-webkit-transition: 0.5s;
transition: 0.5s;
}
<div class="radio_button"></div>