Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <table id="target-table">
  <thead>
    <tr>
      <th>選択欄</th>
      <th>2列目</th>
      <th>3列目</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>
        <input type="radio" required="required" name="radios" value="1">
      </td>
      <td>1-1</td>
      <td>1-2</td>
    </tr>
    <tr>
      <td>
        <input type="radio" required="required" name="radios" value="2">
      </td>
      <td>2-1</td>
      <td>2-2</td>
    </tr>
    <tr>
      <td>
        <input type="radio" required="required" name="radios" value="3">
      </td>
      <td>3-1</td>
      <td>3-2</td>
    </tr>
  </tbody>
</table>
              
            
!

CSS

              
                table {
  margin: 0 0 2em 0;
  width: 100%;
}
table tbody tr {
  border: solid 1px rgba(210, 215, 217, 0.75);
  border-left: 0;
  border-right: 0;
}
table tbody tr:nth-child(2n + 1) {
  background-color: rgba(230, 235, 237, 0.25);
}
table td {
  padding: 0.75em 0.75em;
}
table th {
  color: #3d4449;
  font-size: 0.9em;
  font-weight: 600;
  padding: 0 0.75em 0.75em 0.75em;
  text-align: left;
}

              
            
!

JS

              
                function preloader() {
  let table = document.getElementById("target-table");
  let rows = table.querySelectorAll("tbody tr");

  let backgroundcolor_dict = {};
  let tr_color = window.getComputedStyle(rows[0], "").color;

  rows.forEach((row) => {
    // 行ごとに背景色が異なるため全ての行の変更前の背景色を取得
    backgroundcolor_dict[String(row.rowIndex)] = window.getComputedStyle(
      row,
      ""
    ).backgroundColor;

    row.addEventListener(
      "click",
      function () {
        // 一度全て元の配色
        rows.forEach((click_row) => {
          click_row.style.backgroundColor =
            backgroundcolor_dict[String(row.rowIndex)];
          click_row.style.color = tr_color;
        });
        // 選択された行のみ配色変更
        row.style.backgroundColor = "#0A9BCD";
        row.style.color = "#FFFFFF";

        if (row.querySelector("input").type == "radio") {
          row.querySelector('input[type="radio"]').checked = true;
        }
        if (row.querySelector("input").type == "checkbox") {
          if (row.querySelector('input[type="checkbox"]').checked == false) {
            row.querySelector('input[type="checkbox"]').checked = true;
          } else {
            row.querySelector('input[type="checkbox"]').checked = false;
          }
        }
      },
      false
    );
  });
}

window.onload = preloader;

              
            
!
999px

Console