简体   繁体   中英

Semicolon syntax in jquery has me baffled

In the fairly simple code:

<script> 
    $(document).ready(function () {
        $('.showprice').click(function () {
            $(this).parent.children.hide();
        }); 
    })
 </script>

Jshints in Fiddle fusses about the first line, saying, missing ; and fusses at the last line with unrecoverable error.

Q1: What am I missing here. My suspicion is that it's like perl, and is complaining about a semicolon when there is something entirely different wrong.

Q2: Pointers or links to better methods for tracking down syntax errors.


Based on the first reply below, I made the changes suggested, bring the code up to this:

I edited the code to be:

1 < script > 
2     $(document).ready(function () {
3     $('.showprice').click(function () {
4         $(this).parent().children().hide();
5     }); 
6    });
7    < /script>

And now I get fusses about missing ; on line 1, "expected assignment or function call on line 6
and unrecoverable error on line 7.

Firstly, you should change:

$(this).parent.children.hide();

to:

$(this).parent().children().hide();

parent() and children() is a method. You need () here.

You also need to add ; after closing }) of your DOM ready wrapper, final code should look like this:

$(document).ready(function () {
    $('.showprice').click(function () {
        $(this).parent().children().hide();
    }); 
}); // <-- Here

You forgot to put ; on the last ) of the code:

$(document).ready(function () {
    $('.showprice').click(function () {
        $(this).parent.children.hide();
    }); 
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM