Rhys Edwards Rhys Edwards - 4 years ago 91
Javascript Question

Card not flipping due to uncaught reference error

I have a card that displays one content on one side and different content when it's flipped. The flip is triggered with an onClick call on an

a
tag. However, I'm getting caught up on an uncaught reference error for
flip
. What steps should I take to debug this? I've double-checked the syntax for the html and JS (everything seems to be fine).

HTML

p.footer: #[a(href='#', onclick='flip()') About #[span]]


JS

$(document).ready(function () {

// FLIP IT

function flip () {
$('.card').toggleClass('about');
}

});


Error

Uncaught ReferenceError: flip is not defined
onclick @ (index):1

Answer Source

flip() is local to $(document).ready , you can't access with onclick='flip()'.

it would be better to use jquery to assign the handler in ready().

$('p.footer a:contains(About)').click(flip);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download