1

I'm having a little problem with JavaScript and wondered whether you could help me. I have an image and a video. I want to be able to click the image and to make the video at half transparency. I can't quite see why my code doesn't work.

Image

<img src="James Outlined.jpg" id="picture_on">

iFrame

<iframe width="630" height="350" src="https://www.youtube.com/embed/MmB9b5njVbA" frameborder="0" allowfullscreen id="MinecraftVideo"></iframe>

JavaScript code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js">

    $(document).ready(function(){
    $(“#picture_on”).click(function(){
    $(“#MinecraftVideo”).animate({
    opacity: '0.5'
        });
      });
    });

</script>
6
  • have you got any error?? Commented May 30, 2015 at 9:56
  • Don't use Multibyte characters as delimiter. Change to ". Commented May 30, 2015 at 9:58
  • Code is okay: jsfiddle.net/72urv0t4 Commented May 30, 2015 at 9:58
  • Code is not okey, cause its not valide! Check the delimiters. Commented May 30, 2015 at 9:59
  • I am running the html doc containing the code, in chrome. However, when I click on the pic, there is no change to the transparency of the video. Commented May 30, 2015 at 10:00

2 Answers 2

8

You have some JavaScript syntax error's in your codes.

$(“#picture_on”)

Don't use multibyte characters as delimiters. Change to " or '. Until using the right syntax, your code is working fine. Check this Fiddle.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js">
$(document).ready(function(){
    $("#picture_on").click(function(){
        $("#MinecraftVideo").animate({
            opacity: '0.5'
        });
    });
});
</script>
Sign up to request clarification or add additional context in comments.

Comments

0

JavaScript image as a button:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
    $(document).ready(function(){
        $("#picture_on").click(function(){
            $("#MinecraftVideo").animate({
                opacity: '0.5'
            });
        });
    });
</script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.