0

I need to test each parameter function for console, but it generates me an error: "invert is not defined"

function invert(container) {
    var element = $('.container').eq(container-1);
    if (element.css('text-align') == 'right') {
        element.css('text-align', 'left');
    } else {
        element.css('text-align', 'right');
    }
}

console

invert(4);
ReferenceError: invert is not defined

jsfiddle

Cristiano Matos
  • 329
  • 1
  • 2
  • 10
  • I have checked it jsfiddle. Its working. Your function is called properly. – Manish J Sep 05 '14 at 05:07
  • The fiddle you posted doesn't generate the error you've mentioned, though I'd suspect the issue similar to "[Simple example doesn't work on JSFiddle](http://stackoverflow.com/questions/5431351/simple-example-doesnt-work-on-jsfiddle)" – Jonathan Lonowski Sep 05 '14 at 05:07
  • I can not just call the function with parameter? – Cristiano Matos Sep 05 '14 at 05:08
  • If you are trying to execute the method from the browser console it won't work because the method is not in the main global scope... it is in the scope of the result window(actually not in the global scope at all, it is in a closure scope) – Arun P Johny Sep 05 '14 at 05:11
  • 2
    If you mean you can't invoke it from the console, that's because `invert()` isn't a global. This is due to the **`onLoad`** option selected in JSFiddle. Try changing that to either of the `No wrap` options. You may also have to [choose a different frame for the console](http://stackoverflow.com/questions/3275816/debugging-iframes-with-chrome-developer-tools) since JSFiddle makes use of multiple iframes. – Jonathan Lonowski Sep 05 '14 at 05:12
  • Jsfiddle wrap this block of area in iframe. Calling a function from IFRAME is a bit tricky cause of origin scope errors. Check this http://stackoverflow.com/questions/251420/invoking-javascript-code-in-an-iframe-from-the-parent-page – kazimt9 Sep 05 '14 at 05:15

0 Answers0