Rectangle 27 97

$('.menuOption').click(function( event ){ // <---- "event" parameter here

    event.preventDefault();
    var categories = $(this).attr('rel');
    $('.pages').hide();
    $(categories).fadeIn();


});

You need "event" to be a parameter to the handlers. WebKit follows IE's old behavior of using a global symbol for "event", but Firefox doesn't. When you're using jQuery, that library normalizes the behavior and ensures that your event handlers are passed the event parameter.

edit to clarify: you have to provide some parameter name; using event makes it clear what you intend, but you can call it e or cupcake or anything else.

Note also that the reason you probably should use the parameter passed in from jQuery instead of the "native" one (in Chrome and IE and Safari) is that that one (the parameter) is a jQuery wrapper around the native event object. The wrapper is what normalizes the event behavior across browsers. If you use the global version, you don't get that.

Great thanks. meteor.js uses alot of event vars. function(){.... without passing event still works in chrome and safari. however firefox would fail.

javascript - ReferenceError: event is not defined error in Firefox - S...

javascript jquery html firefox
Rectangle 27 41

It is because you forgot to pass in event into the click function:

$('.menuOption').on('click', function (e) { // <-- the "e" for event

    e.preventDefault(); // now it'll work

    var categories = $(this).attr('rel');
    $('.pages').hide();
    $(categories).fadeIn();
});

On a side note, e is more commonly used as opposed to the word event since Event is a global variable in most browsers.

... except in Firefox of course! It doesn't hurt to use the name "event" for the parameter, as it's not a reserved word or anything.

It worked in first attempt, thanx

javascript - ReferenceError: event is not defined error in Firefox - S...

javascript jquery html firefox
Rectangle 27 6

You appear to be trying to use the odd global event object that is a legacy of the 4.0-browser-era Microsoft event model. Don't. Use the standard event object instead. It will be the first argument to your event handler function.

jQuery('selector').on('click', function (evt) {
    jQuery("#tooltip").animate({ left: evt.clientX, top: evt.clientY });
});

still not working !!!!!!!!

@mothana it should work. You are doing something wrong somewhere in your 'not posted' code

javascript - ReferenceError: event is not defined in Firefox - Stack O...

javascript jquery firefox
Rectangle 27 2

Mothana, Quentin is right,almost. I work with d3.js (jQuery like library) and the old story browser thing is that events that are not declared are not acceptable. So you have 3 weays to solve this:

2. Use the standard event object of your function

tooltip.style("top", (event.pageY-10)+"px").style("left",(event.pageX+10)+"px"))

and i used the d3.js object named "d3" to make the selection of the event for me (working code):

tooltip.style("top", (d3.event.pageY-10)+"px").style("left",(d3.event.pageX+10)+"px")

So I suppose in jQuery you must use the name of your javascript library object, something like jQuery.someSelection().

javascript - ReferenceError: event is not defined in Firefox - Stack O...

javascript jquery firefox
Rectangle 27 1

Not sure if it worked in Firefox because I don't want to use Firefox.

<!DOCTYPE html> 
<html>
  <head>
    <title>Test A</title>
    <script>
      function showCoords(evt){
        alert(
          "clientX value: " + evt.clientX + "\n" +
          "clientY value: " + evt.clientY// + "\n"
        );
    	}
      function begin(){
        parag = document.getElementById("parag");
        parag.addEventListener("click", function(e) {showCoords(e);}, false);
      }
    </script>
  </head>
  <body onload="begin()">
    <p id="parag">To display the mouse coordinates click in this paragraph.</p>
  </body>
</html>

javascript - ReferenceError: event is not defined - Firefox - Stack Ov...

javascript html firefox mouseevent
Rectangle 27 3

The Firefox add-on SDK uses modules that need to be imported into main.js using the require function. There is no global Worker object, as the error is pretty explicit about. A content script needs to be attached to an HTML page somewhere; it can't exist alone. The three most common ways to get a worker are by attaching a content script to

var tabs = require("sdk/tabs");

tabs.on('ready', function(tab) {
  var worker = tab.attach({
      contentScript:
        'document.body.style.border = "5px solid red";'
  });
});

any page that matches an array of URLs or regex, using a PageMod

var tag = "p";
var data = require("sdk/self").data;
var pageMod = require("sdk/page-mod");

pageMod.PageMod({
  include: "*.mozilla.org",
  contentScriptFile: data.url("element-getter.js"),
  onAttach: function(worker) {
    worker.port.emit("getElements", tag);
    worker.port.on("gotElement", function(elementContent) {
      console.log(elementContent);
    });
  }
});

an invisible background page with PageWorker, which is probably what you're going for

pageWorker = require("sdk/page-worker").Page({
  contentScript: "console.log(document.body.innerHTML);",
  contentURL: "http://en.wikipedia.org/wiki/Internet"
});

Note that panels work very similarly to workers in that they have onMessage and port attributes.

Note also that onMessage is spelt with a capital M

javascript - ReferenceError: Worker is not defined in simple Firefox E...

javascript firefox firefox-addon firefox-addon-sdk web-worker
Rectangle 27 2

In Firefox Addon, use ChromeWorker instead of worker.

Add the following lines in main.js

var { ChromeWorker } = require("chrome");
var self = require("sdk/self");
var data = self.data;

var localWorker = new ChromeWorker(data.url("my_worker.js"));

worker.onmessage = function(e) {
    console.log(e.data);
};

worker.postMessage("Bobby");
self.onmessage = function(e) {
    self.postMessage("Hello " + e.data);
};

put your my_worker.js file in data/ directory.

any idea how to get the webworker importScripts function working for chrome workers?

javascript - ReferenceError: Worker is not defined in simple Firefox E...

javascript firefox firefox-addon firefox-addon-sdk web-worker
Rectangle 27 3

yes I had made some changes trying to fix the problem after posting the markup and before taking the screenshot... good observation... those changes (moving the script into the head) didn't make a difference.

+1 for the observation that $ is not defined when you try to use it, that was in fact the problem, the root cause though was that it had not downloaded jQuery for some security related reason (which I don't understand).

@amdn The error you see is generated because you're trying to load from a unsecure HTTP protocol and inject into a page on secure HTTPS protocol. If you remove the protocol from the script tag, the browser shouldn't complain anymore.

@Ragnarokkr I think you are right, however, if I remove HTTPS from the url it gets inserted anyways on all three browsers, yet Chrome is the only one that complains about it the url for jquery being insecure.

javascript - "Uncaught ReferenceError: $ is not defined" error on Goog...

javascript jquery google-chrome firefox safari
Rectangle 27 70

What's the difference between let and var?

  • A variable defined using a var statement is known throughout the function it is defined in, from the moment it is defined onward.
  • A variable defined using a let statement is only known in the block it is defined in, from the moment it is defined onward.

To understand the difference, consider the following code:

function loop(arr) {
    // i IS NOT known here
    // j IS NOT known here

    for( var i = 0; i < arr.length; i++ ) {
        // i IS known here
    }

    // i IS known here
    // j IS NOT known here

    for( let j = 0; j < arr.length; j++ ) {
        // j IS known here
    }

    // i IS known here
    // j IS NOT known here
}

Here, we can see that our variable j is only known in the first for loop, but not before and after. Yet, our variable i is known in the entire function from the moment it is defined onward.

Some people would argue that in the future we'll ONLY use let statements and that var statements will become obsolete. JavaScript guru Kyle Simpson wrote a very elaborate article on why that's not the case.

Today, however, that is definitely not the case. In fact, we need actually to ask ourselves whether it's safe to use the let statement. The answer to that question depends on your environment:

If you're writing server-side JavaScript code (Node.js), you can safely use the let statement.

If you're writing client-side JavaScript code and don't use a transpiler, you need to consider browser support.

let

For an up-to-date overview of which browsers support the let statement at the time of your reading this answer, see this Can I Use page.

regarding answer v4: i IS known everywhere in the function-block! It starts as undefined (due to hoisting) until you assign a value! ps: let is also hoisted (to the top of it's containing block), but will give a ReferenceError when referenced in the block before first assignment. (ps2: I'm a pro-semicolon kinda guy but you really don't need a semicolon after a block ). That being said, thanks for adding the reality-check regarding support!

javascript - What's the difference between using "let" and "var" to de...

javascript scope ecmascript-6 var let
Rectangle 27 70

What's the difference between let and var?

  • A variable defined using a var statement is known throughout the function it is defined in, from the moment it is defined onward.
  • A variable defined using a let statement is only known in the block it is defined in, from the moment it is defined onward.

To understand the difference, consider the following code:

function loop(arr) {
    // i IS NOT known here
    // j IS NOT known here

    for( var i = 0; i < arr.length; i++ ) {
        // i IS known here
    }

    // i IS known here
    // j IS NOT known here

    for( let j = 0; j < arr.length; j++ ) {
        // j IS known here
    }

    // i IS known here
    // j IS NOT known here
}

Here, we can see that our variable j is only known in the first for loop, but not before and after. Yet, our variable i is known in the entire function from the moment it is defined onward.

Some people would argue that in the future we'll ONLY use let statements and that var statements will become obsolete. JavaScript guru Kyle Simpson wrote a very elaborate article on why that's not the case.

Today, however, that is definitely not the case. In fact, we need actually to ask ourselves whether it's safe to use the let statement. The answer to that question depends on your environment:

If you're writing server-side JavaScript code (Node.js), you can safely use the let statement.

If you're writing client-side JavaScript code and don't use a transpiler, you need to consider browser support.

let

For an up-to-date overview of which browsers support the let statement at the time of your reading this answer, see this Can I Use page.

regarding answer v4: i IS known everywhere in the function-block! It starts as undefined (due to hoisting) until you assign a value! ps: let is also hoisted (to the top of it's containing block), but will give a ReferenceError when referenced in the block before first assignment. (ps2: I'm a pro-semicolon kinda guy but you really don't need a semicolon after a block ). That being said, thanks for adding the reality-check regarding support!

javascript - What's the difference between using "let" and "var" to de...

javascript scope ecmascript-6 var let
Rectangle 27 70

What's the difference between let and var?

  • A variable defined using a var statement is known throughout the function it is defined in, from the moment it is defined onward.
  • A variable defined using a let statement is only known in the block it is defined in, from the moment it is defined onward.

To understand the difference, consider the following code:

function loop(arr) {
    // i IS NOT known here
    // j IS NOT known here

    for( var i = 0; i < arr.length; i++ ) {
        // i IS known here
    }

    // i IS known here
    // j IS NOT known here

    for( let j = 0; j < arr.length; j++ ) {
        // j IS known here
    }

    // i IS known here
    // j IS NOT known here
}

Here, we can see that our variable j is only known in the first for loop, but not before and after. Yet, our variable i is known in the entire function from the moment it is defined onward.

Some people would argue that in the future we'll ONLY use let statements and that var statements will become obsolete. JavaScript guru Kyle Simpson wrote a very elaborate article on why that's not the case.

Today, however, that is definitely not the case. In fact, we need actually to ask ourselves whether it's safe to use the let statement. The answer to that question depends on your environment:

If you're writing server-side JavaScript code (Node.js), you can safely use the let statement.

If you're writing client-side JavaScript code and don't use a transpiler, you need to consider browser support.

let

For an up-to-date overview of which browsers support the let statement at the time of your reading this answer, see this Can I Use page.

regarding answer v4: i IS known everywhere in the function-block! It starts as undefined (due to hoisting) until you assign a value! ps: let is also hoisted (to the top of it's containing block), but will give a ReferenceError when referenced in the block before first assignment. (ps2: I'm a pro-semicolon kinda guy but you really don't need a semicolon after a block ). That being said, thanks for adding the reality-check regarding support!

javascript - What's the difference between using "let" and "var" to de...

javascript scope ecmascript-6 var let
Rectangle 27 70

What's the difference between let and var?

  • A variable defined using a var statement is known throughout the function it is defined in, from the moment it is defined onward.
  • A variable defined using a let statement is only known in the block it is defined in, from the moment it is defined onward.

To understand the difference, consider the following code:

function loop(arr) {
    // i IS NOT known here
    // j IS NOT known here

    for( var i = 0; i < arr.length; i++ ) {
        // i IS known here
    }

    // i IS known here
    // j IS NOT known here

    for( let j = 0; j < arr.length; j++ ) {
        // j IS known here
    }

    // i IS known here
    // j IS NOT known here
}

Here, we can see that our variable j is only known in the first for loop, but not before and after. Yet, our variable i is known in the entire function from the moment it is defined onward.

Some people would argue that in the future we'll ONLY use let statements and that var statements will become obsolete. JavaScript guru Kyle Simpson wrote a very elaborate article on why that's not the case.

Today, however, that is definitely not the case. In fact, we need actually to ask ourselves whether it's safe to use the let statement. The answer to that question depends on your environment:

If you're writing server-side JavaScript code (Node.js), you can safely use the let statement.

If you're writing client-side JavaScript code and don't use a transpiler, you need to consider browser support.

let

For an up-to-date overview of which browsers support the let statement at the time of your reading this answer, see this Can I Use page.

regarding answer v4: i IS known everywhere in the function-block! It starts as undefined (due to hoisting) until you assign a value! ps: let is also hoisted (to the top of it's containing block), but will give a ReferenceError when referenced in the block before first assignment. (ps2: I'm a pro-semicolon kinda guy but you really don't need a semicolon after a block ). That being said, thanks for adding the reality-check regarding support!

javascript - What's the difference between using "let" and "var" to de...

javascript scope ecmascript-6 var let
Rectangle 27 69

What's the difference between let and var?

  • A variable defined using a var statement is known throughout the function it is defined in, from the moment it is defined onward.
  • A variable defined using a let statement is only known in the block it is defined in, from the moment it is defined onward.

To understand the difference, consider the following code:

function loop(arr) {
    // i IS NOT known here
    // j IS NOT known here

    for( var i = 0; i < arr.length; i++ ) {
        // i IS known here
    }

    // i IS known here
    // j IS NOT known here

    for( let j = 0; j < arr.length; j++ ) {
        // j IS known here
    }

    // i IS known here
    // j IS NOT known here
}

Here, we can see that our variable j is only known in the first for loop, but not before and after. Yet, our variable i is known in the entire function from the moment it is defined onward.

Some people would argue that in the future we'll ONLY use let statements and that var statements will become obsolete. JavaScript guru Kyle Simpson wrote a very elaborate article on why that's not the case.

Today, however, that is definitely not the case. In fact, we need actually to ask ourselves whether it's safe to use the let statement. The answer to that question depends on your environment:

If you're writing server-side JavaScript code (Node.js), you can safely use the let statement.

If you're writing client-side JavaScript code and don't use a transpiler, you need to consider browser support.

let

For an up-to-date overview of which browsers support the let statement at the time of your reading this answer, see this Can I Use page.

regarding answer v4: i IS known everywhere in the function-block! It starts as undefined (due to hoisting) until you assign a value! ps: let is also hoisted (to the top of it's containing block), but will give a ReferenceError when referenced in the block before first assignment. (ps2: I'm a pro-semicolon kinda guy but you really don't need a semicolon after a block ). That being said, thanks for adding the reality-check regarding support!

javascript - What's the difference between using "let" and "var" to de...

javascript scope ecmascript-6 var let
Rectangle 27 69

What's the difference between let and var?

  • A variable defined using a var statement is known throughout the function it is defined in, from the moment it is defined onward.
  • A variable defined using a let statement is only known in the block it is defined in, from the moment it is defined onward.

To understand the difference, consider the following code:

function loop(arr) {
    // i IS NOT known here
    // j IS NOT known here

    for( var i = 0; i < arr.length; i++ ) {
        // i IS known here
    }

    // i IS known here
    // j IS NOT known here

    for( let j = 0; j < arr.length; j++ ) {
        // j IS known here
    }

    // i IS known here
    // j IS NOT known here
}

Here, we can see that our variable j is only known in the first for loop, but not before and after. Yet, our variable i is known in the entire function from the moment it is defined onward.

Some people would argue that in the future we'll ONLY use let statements and that var statements will become obsolete. JavaScript guru Kyle Simpson wrote a very elaborate article on why that's not the case.

Today, however, that is definitely not the case. In fact, we need actually to ask ourselves whether it's safe to use the let statement. The answer to that question depends on your environment:

If you're writing server-side JavaScript code (Node.js), you can safely use the let statement.

If you're writing client-side JavaScript code and don't use a transpiler, you need to consider browser support.

let

For an up-to-date overview of which browsers support the let statement at the time of your reading this answer, see this Can I Use page.

regarding answer v4: i IS known everywhere in the function-block! It starts as undefined (due to hoisting) until you assign a value! ps: let is also hoisted (to the top of it's containing block), but will give a ReferenceError when referenced in the block before first assignment. (ps2: I'm a pro-semicolon kinda guy but you really don't need a semicolon after a block ). That being said, thanks for adding the reality-check regarding support!

javascript - What's the difference between using "let" and "var" to de...

javascript scope ecmascript-6 var let
Rectangle 27 69

What's the difference between let and var?

  • A variable defined using a var statement is known throughout the function it is defined in, from the moment it is defined onward.
  • A variable defined using a let statement is only known in the block it is defined in, from the moment it is defined onward.

To understand the difference, consider the following code:

function loop(arr) {
    // i IS NOT known here
    // j IS NOT known here

    for( var i = 0; i < arr.length; i++ ) {
        // i IS known here
    }

    // i IS known here
    // j IS NOT known here

    for( let j = 0; j < arr.length; j++ ) {
        // j IS known here
    }

    // i IS known here
    // j IS NOT known here
}

Here, we can see that our variable j is only known in the first for loop, but not before and after. Yet, our variable i is known in the entire function from the moment it is defined onward.

Some people would argue that in the future we'll ONLY use let statements and that var statements will become obsolete. JavaScript guru Kyle Simpson wrote a very elaborate article on why that's not the case.

Today, however, that is definitely not the case. In fact, we need actually to ask ourselves whether it's safe to use the let statement. The answer to that question depends on your environment:

If you're writing server-side JavaScript code (Node.js), you can safely use the let statement.

If you're writing client-side JavaScript code and don't use a transpiler, you need to consider browser support.

let

For an up-to-date overview of which browsers support the let statement at the time of your reading this answer, see this Can I Use page.

regarding answer v4: i IS known everywhere in the function-block! It starts as undefined (due to hoisting) until you assign a value! ps: let is also hoisted (to the top of it's containing block), but will give a ReferenceError when referenced in the block before first assignment. (ps2: I'm a pro-semicolon kinda guy but you really don't need a semicolon after a block ). That being said, thanks for adding the reality-check regarding support!

javascript - What's the difference between using "let" and "var" to de...

javascript scope ecmascript-6 var let
Rectangle 27 68

What's the difference between let and var?

  • A variable defined using a var statement is known throughout the function it is defined in, from the moment it is defined onward.
  • A variable defined using a let statement is only known in the block it is defined in, from the moment it is defined onward.

To understand the difference, consider the following code:

function loop(arr) {
    // i IS NOT known here
    // j IS NOT known here

    for( var i = 0; i < arr.length; i++ ) {
        // i IS known here
    }

    // i IS known here
    // j IS NOT known here

    for( let j = 0; j < arr.length; j++ ) {
        // j IS known here
    }

    // i IS known here
    // j IS NOT known here
}

Here, we can see that our variable j is only known in the first for loop, but not before and after. Yet, our variable i is known in the entire function from the moment it is defined onward.

Some people would argue that in the future we'll ONLY use let statements and that var statements will become obsolete. JavaScript guru Kyle Simpson wrote a very elaborate article on why that's not the case.

Today, however, that is definitely not the case. In fact, we need actually to ask ourselves whether it's safe to use the let statement. The answer to that question depends on your environment:

If you're writing server-side JavaScript code (Node.js), you can safely use the let statement.

If you're writing client-side JavaScript code and don't use a transpiler, you need to consider browser support.

let

For an up-to-date overview of which browsers support the let statement at the time of your reading this answer, see this Can I Use page.

regarding answer v4: i IS known everywhere in the function-block! It starts as undefined (due to hoisting) until you assign a value! ps: let is also hoisted (to the top of it's containing block), but will give a ReferenceError when referenced in the block before first assignment. (ps2: I'm a pro-semicolon kinda guy but you really don't need a semicolon after a block ). That being said, thanks for adding the reality-check regarding support!

javascript - What's the difference between using "let" and "var" to de...

javascript scope ecmascript-6 var let
Rectangle 27 1

Move the get_table_filters out of the if statement

if($('#example').length) {
var oTable = $('#listings').dataTable({
    "bProcessing": true,
    "bServerSide": true,
    "sAjaxSource": ajax_url+'?action=load_table_data',
    "fnServerParams": function ( aoData ) {
         aoData.push( { "name": "filters", "value": get_table_filters() } );
    }
});
    var tableFilterArray = {};
}

function get_table_filters() {
    return JSON.stringify(tableFilterArray);
}

javascript - Firefox ReferenceError:... is not defined issue - Stack O...

javascript jquery firefox
Rectangle 27 2

For those wanting to use the window object, you can create it using this code:

var { viewFor } = require("sdk/view/core");
var window = viewFor(require("sdk/windows").browserWindows[0]);

javascript - In a Firefox Add-on how to resolve the error "window is n...

javascript firefox-addon event-listener
Rectangle 27 1

The online builder is an online IDE for developing with the Addon-SDK, where window isn't in global scope -- it's not any specific window.

You can include the tabs module and listen for ready events or activate (a tab is now focused) events, which may be what you want.

let tabs = require('sdk/tabs');
tabs.on('ready', function (tab) {
  console.log(tab.url + ' is ready!');
});

can you please tell me why browser.tabs showing browser is undefined?

javascript - In a Firefox Add-on how to resolve the error "window is n...

javascript firefox-addon event-listener