0

I have a menu with some links which hides/shows div pages.

On the first page I have youtube video playing, but if I click another link, the video dissapears as another div will be showing, but the video keeps playing..

I found the way of how to stop the video etc, but while debugging, I can not seem to make my alert to go off while I write this:

if ( $("#main").css('display') == 'none')
{
    alert("Hello! I am an alert box!!");
}

If I were to change none to block the alert box will appear once the page loads up. So how come it does not show up once the id for main changes to none (when I click another menu link)?

EDITED:

Thats how I set the attributes to none with the menu links:

$('.tabs a').on( "click", function(e) {
    e.preventDefault();
    var id = $(this).attr('data-related'); 
    $(".frame div").each(function(){
        $(this).hide();
        if($(this).attr('id') == id) {
            $(this).show();
        }
    });
});
4
  • Do you explicitly set the display attribute to none? Commented Sep 21, 2016 at 23:56
  • If I set my div id to none it will display the alert on page load, but if I click other menu links which will make #main div change from none to block, then it will not show up again. It shows alert if the if condition matches on page load only, but once is changed withing the page, it will not show up Commented Sep 21, 2016 at 23:59
  • How do you set attribute to none? Commented Sep 22, 2016 at 0:01
  • @L.Kolar see my edit to the original question Commented Sep 22, 2016 at 0:03

1 Answer 1

1

Are you calling a function with that if statement anywhere in your js or do you just have the if statement in your js not inside a function? If you just have the if statement in there it will only evaluate it on page load, it won't keep running the if statement every time the css changes. you need to put the if statement into a function and call that function every time you change the css

Sign up to request clarification or add additional context in comments.

2 Comments

No, its not in the funcion. Well atleast now I know what's the problem. Thanks for that
No problem, can you please upvote and accept my answer?

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.