I’m a little confused as to why my JQuery ‘addClass’ method seems to stop working when placed in a function call.
Blockquote
/* $(“#logo”).addClass(“fade-out”); */
function performSearch() {
$(“#logo”).addClass(“fade-out”);
console.log(“Button has been pressed”);
}
Blockquote
If I un-comment the first line outside of the function one can see ‘addClass’ is working correctly. Further, I know the function is being called correctly because console.log triggers as expected. However for some reason then the addClass does not have the same effect, or seems to do nothing… A little confused…
That seems to work-- But do you have any idea why?!?. Even putting the ‘return statement’ at the end of the ‘performSearch()’ function itself doesn’t seem to work. Seems a little weird-- What is it expecting that adding the return to the call, not even to the function itself, won’t suffice ?
Okay, that makes more sense to me now as otherwise with <form> as with <a href> in the Youtube example the page will try and invoke the default relevant behavior for the tag.
This was not obvious to me at first but makes more sense now. Thanks for your help.