0

I'm new to jquery and javascript in general and am having trouble figuring out the difference between these two code sets. This code works:

$(document).ready(function () {
    $('div.poem-stanza').addClass('highlight');
});

and this code does not

function x() {
    $('div.poem-stanza').addclass('highlight');
}

$(document).ready(x);

giving the error: Uncaught Typeerror: Object #<Object> has no method 'addclass'

Is there something wrong with my function declaration? BTW, the non-working example comes straight from "Learning JQuery, Third Edition" book.

2 Answers 2

4

addclass should be addClass in your second snippet.

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

Comments

4

Javascript is case sensitive. The correct method is .addClass(), not .addclass.

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.