user2295265
user2295265

Reputation: 71

How to merge two scripts and trigger them both at once?

I am writing an website from the scratch probably for the first time and I am stucked in javascript. My idea is to trigger the link by a click which will run two javascripts at once. Here is the situation:

Link to click:

<li><p class="button"><a href="video_iframe.html" target="iframe">VIDEO</a></p></li>

Iframe as a target:

<li><iframe width="800px" height="1000px" frameBorder="0" name="iframe"></iframe></li>

js 1:

<script>
$('.button').click(function () {
$(this).toggleClass('active');
if ($(this).hasClass('active')) {
    $('#zelena').stop().animate({
        left: 151
    });
} else {
    $('#zelena').stop().animate({
        left: -649
    });
}
});
</script>

js 2:

<script>
$(".button").on("click", function() {
$(this).toggleClass("underline");
$(".button").not(this).removeClass("underline");

}); 
</script>

here I uploaded the whole website: http://www.filedropper.com/mgwebslidefinaliframe

(The problem is that I have to click 2 times at "VIDEO" link/button to show the iframe content and that´s the problem, because on the second click It should close like It´s doing right now. So we can´t see the iframe content because of the no needed second click... Thanks in advance for any help.

Upvotes: 0

Views: 129

Answers (2)

Obscure Geek
Obscure Geek

Reputation: 749

You have added the reference to the button. Just add the following attribute to your iframe tag: src="video_iframe.html" and remove the a tag added to the button. I think this should solve your issue.

Upvotes: 0

PeterKA
PeterKA

Reputation: 24638

$('.button').on('click', function () {
    $(this).toggleClass('active underline');
    $(".button.underline").not(this).removeClass("underline");
    if($(this).hasClass('active')) {
        $('#zelena').stop().animate({
            left: 151
        });
    } else {
        $('#zelena').stop().animate({
            left: -649
        });
    }
}); 

Upvotes: 1

Related Questions