How I do I make a bookmark in google chrome the select the element ID of a radio button

108 Views Asked by At

I want to make a bookmarklet that click the Id value of a radio button on this page I want it to select - Option 2

I've created a bookmarklet in google chrome and used this code

document.getElementsByClassName('mat-radio-2-input')[1].checked = true

but when I click the bookmark, it does nothing I want it to select "Option 2" elementId.

1

There are 1 best solutions below

1
LS_ On

If you inspect the page you can see that Option 2 has id mat-radio-3-input, you can use this code to select it via a bookmark:

javascript:(function() {  var radioButton = document.getElementById('mat-radio-3-input'); if (radioButton) {    radioButton.checked = true;  } else {    alert('Radio button not found.');  }})();