Leandros Leandros - 1 year ago 46
jQuery Question

In jQuery i cant find out how to change attr again and again

Ι can't find how when I get click into the circle to change the attr again and again.for those two attr. I'm new to code obviously!Thank you all for the quick responce.

<body>

<iframe width="560" height="315" src="https://www.youtube.com/embed/5SgyFaBS7WI" frameborder="0" allowfullscreen></iframe>

<div id="circle"></div>


<script type="text/javascript">

$("#circle").click(function() {

$("iframe").attr("src", <iframe width="560" height="315" src="https://www.youtube.com/embed/0WazFtJSIHk" frameborder="0" allowfullscreen></iframe>, function("src","https://www.youtube.com/embed/5SgyFaBS7WI");

});



</script>

</body>



Answer Source
<body>

<iframe width="560" height="315" src="https://www.youtube.com/embed/5SgyFaBS7WI" frameborder="0" allowfullscreen></iframe>

<div id="circle">Click me</div>

<script
  src="https://code.jquery.com/jquery-2.2.4.min.js"
  integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="
  crossorigin="anonymous"></script>
<script type="text/javascript">

    $(document).ready(function() {
        var links = [
            "https://www.youtube.com/embed/0WazFtJSIHk",
            "https://www.youtube.com/embed/5SgyFaBS7WI"
        ];

        var counter = 0;

        $("#circle").click(function() {
            $("iframe").attr("src", links[counter % links.length]);
            counter++;
        });
      });

</script>

</body>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download