Reputation: 3896
How can I achieve this?
for each pages I have attached a unique class-name so I can target them by css later.
I want to run a function but only targeting the homepage.
eg.
if($('body').hasClass('pageHome')) {
callMe;
}
function callMe() {
alert('I am Home!');
}
Upvotes: 1
Views: 42
Reputation: 171669
Concept should work fine as long as you are wrapping code in
$(function(){ /* run code*/ })
and you need to add "()" to callme();
Upvotes: 0
Reputation: 83356
It looks like you're close. To call callMe
, you'll want parenthesis to indicate that it's a function call:
if($('body').hasClass('pageHome')) {
callMe();
}
Upvotes: 1
Reputation: 76003
Your forgot the parenthesis when you called callMe
:
function callMe() {
alert('I am Home!');
}
if($('body').hasClass('pageHome')) {
callMe();
}
Does that help?
Upvotes: 1