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"
    – Avdept
    Jul 25, 2012 at 15:30
  • jshint can help with this kind of thing. 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.
    – user1106925
    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
    – Avdept
    Jul 25, 2012 at 15:36

3 Answers 3

2

change:

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

to:

if (jQuery("#colorbox").css("display") == 'none')
1
if (jQuery("#colorbox").css("display", "none")) {
    jQuery("#close-news").css("display", "none");
} 
else {
    jQuery("#close-news").css("display", "visible");
}
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);        
});

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.