DEV Community

Max
Max

Posted on

Dynamic select works only for the first time and doesn't work anymore in a trivial jQuery example

$(document).ready(function () {
  $("#block_1").change((e) => {
    console.log("block_1 select ", e.target.value);

    $("#children_1")
      // .find("[value!='" + e.target.value + "']")
      .find("option")
      .removeAttr("selected");
    $("#children_1")
      .find("[value='" + e.target.value + "']")
      .attr("selected", true);
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>jQuery</title>
    <script src="js/jquery-2.1.1.min.js"></script>
    <script src="js/script.js"></script>
  </head>
  <body

Top comments (0)