I'm trying to call a function in two different event handlers. The function runs, but doesn't seem to recognize the passed variable ( or maybe the variable isn't getting passed). It just triggers the alert "nothing".

I'm not understanding how to use console.log() or where exactly to look and see what's going on?

Right now, I put it in the function, like I'm showign below. When I test the page in firefox, I go to Firebug, and click on console. I clear everything, then trigger the event, and I'm not sure what I'm looking at... or if I'm even looking in the right place. Or if I even put console.log() in the right place?

Here's what I have

function pic_shift(){

$("#testit").removeClass("main_page");

    if ( $(this).hasClass('active') ) {

            /*  do stuff  */
        } else if ( $(this).hasClass('one') || $(this).hasClass('ee')) {

        /*  do other stuff  */

        } else {        
            alert('nothing');
            console.log($(this));
        };

}

$('.square-container,.main-nav,.reg3,.privacy_policy,.subnav').on('click', '.square','.main', function(event)  {    

    pic_shift( $(this));        

});

:

When I look at console, I see in "all" this: Object[Window #]

When I look at errors, I see nothing.

I should add that when the function isn't separated out and called, it works perfectly fine, and knows what 'this' is.

but doesn't seem to recognize the passed variable ( or maybe the variable isn't getting passed)

first thing I see - its not passed. I mean you pass it, but you have to have it in funciton parameters:

your code:

function pic_shift(){

with parameter should be something like:

function pic_shift(param){

then I assume you want to do actions with the thing you passed as parameter. So probably code should look like this:

    function pic_shift(param){

$("#testit").removeClass("main_page");
    if ( param.hasClass('active') ) {
            /*  do stuff  */
        } else if (param.hasClass('one') || param.hasClass('ee')) {
        /*  do other stuff  */
        } else {        
            alert('nothing');
            console.log(param);
        };
}

Not tested, but probably you get the idea.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.