Home > OS >  javascript radio button check it youtube. how to check it
javascript radio button check it youtube. how to check it

Time:10-17

i want to auto check the radio button ( public ) on youtube.

here is partial code i got

<tp-yt-paper-radio-button name="PUBLIC"  role="radio" tabindex="-1" toggles="" aria-checked="false" aria-disabled="false" aria-selected="false"><!--css_build_mark:third_party.javascript.youtube_components.tp_yt_paper_radio_button.tp.yt.paper.radio.button.css.js--><!--css_build_scope:tp-yt-paper-radio-button--><!--css_build_styles:third_party.javascript.youtube_components.tp_yt_paper_radio_button.tp.yt.paper.radio.button.css.js--><div id="radioContainer" style-target="container" ><div id="offRadio" ></div><div id="onRadio" ></div><paper-ripple id="ink" center="" >
    

    <div id="background"  style="opacity: 0;"></div>
    <div id="waves" ></div>
</paper-ripple></div><div id="radioLabel" style-target="label" >Public</div></tp-yt-paper-radio-button>

i want to auto check the public radio button.

var radios = document.getElementsByTagName('PUBLIC');
for(i=0; i<radios.length; i   ) {
    radios[i].onclick = function(e) {
        if(e.ctrlKey || e.metaKey) {
            this.checked = false;
        }
    }
}

not working

also tried

var radios = document.querySelectorAll('tp-yt-paper-radio-button[name="PUBLIC"]');
for(i=0; i<radios.length; i   ) {
    radios[i].onclick = function(e) {
        if(e.ctrlKey || e.metaKey) {
            this.checked = false;
        }
    }
}

not working

new update not working

var radios = document.querySelectorAll('tp-yt-paper-radio-button[name="PUBLIC"]');
for(i=0; i<radios.length; i   ) {
    radios[i].onclick = function(e) {
        if(e.ctrlKey || e.metaKey) {
            radios[I].checked = true
        }
    }
}

i think to make this work, try set the index of the radio ?

<tp-yt-paper-radio-button name="PUBLIC"  role="radio" tabindex="-1" toggles="" aria-checked="false" aria-

ok this works code below however the unlisted radio remains checked.

var radios = document.querySelectorAll('tp-yt-paper-radio-button[name="PUBLIC"]');
for(i=0; i<radios.length; i   ) {
radios[i].checked = true;
}

and also i dont think it validates or invokes a click just sets it to public. this is why it shows as unlisted still.

=============

new update again working.

var radios = document.querySelectorAll('tp-yt-paper-radio-button[name="PUBLIC"]');
for(i=0; i<radios.length; i   ) {
radios[i].click();
radios[i].checked = true
}

i think this did it. i need to now press the ok button

CodePudding user response:

getElementsByTagName function is used to get elements by TAG name. In your case it is tp-yt-paper-radio-button and not PUBLIC.

EDIT: I see you updated. In your second case, did you try to use checked = true?

CodePudding user response:

var radios = document.querySelectorAll('tp-yt-paper-radio-button[name="PUBLIC"]');
for(i=0; i<radios.length; i   ) {
radios[i].click();
radios[i].checked = true;
}
  • Related