0

I wrote some small script, but since I did it with Google help I need some advice. After putting this into Chrome console, I'm getting this error:

SyntaxError: Unexpected identifier

Here is my code:

jQuery(document).ready(function(){ 
    if jQuery("#colorbox").css("display", "none");) {
        jQuery("#close-news").css("display", "none");
    } 
    else {
        jQuery("#close-news").css("display", "visible");
    }
});

Any ideas what's wrong?

4
  • i have div with id colorbox and style="display: none" Commented Jul 25, 2012 at 15:30
  • jshint can help with this kind of thing. Commented Jul 25, 2012 at 15:32
  • 2
    If you get a SyntaxError, that means you have a SyntaxError, and need to take a close look at your code, and correct the invalid JavaScript. Commented Jul 25, 2012 at 15:32
  • the script is works now, but i dont see any changes on my page. Was it correct to to use .css on colorbox id, while it has .style in code Commented Jul 25, 2012 at 15:36

3 Answers 3

2

change:

if jQuery("#colorbox").css("display", "none");)

to:

if (jQuery("#colorbox").css("display") == 'none')
Sign up to request clarification or add additional context in comments.

Comments

1
if (jQuery("#colorbox").css("display", "none")) {
    jQuery("#close-news").css("display", "none");
} 
else {
    jQuery("#close-news").css("display", "visible");
}

Comments

0

Another way to write it with the syntax errors fixed:

jQuery(function () {
    if (jQuery("#colorbox").is(":visible")) {
        jQuery("#close-news").css("display", "none");
    } else {
        jQuery("#close-news").css("display", "visible");
    }
});

and even simpler with toggle

jQuery(function () {
    var isVisible = jQuery("#colorbox").is(":visible")) {
    jQuery("#close-news").toggle(!isVisible);        
});

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.