Pete Norris
Pete Norris

Reputation: 1054

jQuery syntax error with unexpected token

Sorry for basic... I expect some pro's will mark me down - again, however I have been struggling to see the error of my ways:

Unexpected token { is my error, and the code is:

  <script>
$(document).ready(function {
  $('people.img').click(function() {
    $('.peopleSummary').addClass('hello');
  })
});

Thanks!

Upvotes: -1

Views: 815

Answers (3)

Sergio
Sergio

Reputation: 28845

There is no html element called people, this is a incorrect selector

 $('people.img')

Also to define a function you need (), otherwise you get also a syntax error

$(document).ready(function {

So try this, assuming your people is a class (otherwise use # for a ID):

$(document).ready(function(){
  $('.people.img').click(function() {
    $('.peopleSummary').addClass('hello');
  })
});

Upvotes: 2

Rajaprabhu Aravindasamy
Rajaprabhu Aravindasamy

Reputation: 67217

If people is a class then try

$(document).ready(function(){
  $('.people.img').click(function() {
    $('.peopleSummary').addClass('hello');
  })
});

If it is an id try,

$(document).ready(function(){
  $('#people.img').click(function() {
    $('.peopleSummary').addClass('hello');
  })
});

Upvotes: 1

Arun P Johny
Arun P Johny

Reputation: 388446

$(document).ready(function() {//<-- missig () after function
    $('people.img').click(function () {
        $('.peopleSummary').addClass('hello');
    })
});

Upvotes: 3

Related Questions