Skip to content Skip to sidebar Skip to footer

How To Make Onchange Event In Polymer

I'm getting this message TypeError: document.addEventListener(...) is not a function (document.addEventListener('polymer-ready',function($){ console.log('ready') // top link

Solution 1:

Your code is not valid you are treating the document.addEventListener as an IIFE which it is not. You are executing the (jQuery) at the wrong location.

Solution 2:

You pass jQuery into the immediate function not into the event listener.

(function ($) {
  document.addEventListener('polymer-ready', function () {
    console.log('ready')
    // top link
    $.each(decodeURI(location.pathname).split('/'), function () {
      $("#self").html(this + '');
    });

    // browser default langvar default_lang = navigator.language/* Mozilla */ || navigator.userLanguage/* IE */;

    // does URL contain lang=xx ?
    $.each(decodeURI(location.search.substr(1)).split('&'), function () {
      var s = this.split('=');
      if (s[0] == "lang") { default_lang = s[1] };
    });

    // toplevel = earth
    $("#earth").click(
      function (e) {
        e.preventDefault();
        //location.href = "http://www.geonames.org";
      }
      );

    // entry pointgeo_click($("#earth"));
  });
})(jQuery);

Solution 3:

Problem Solved!

functiongeoready(){
console.log('ready');
// top link
$.each(decodeURI(location.pathname).split('/'), function() {
  $("#self").html(this+'');
});

// browser default lang
default_lang = navigator.language/* Mozilla */ || navigator.userLanguage/* IE */;

// does URL contain lang=xx ?
$.each(decodeURI(location.search.substr(1)).split('&'), function() {
    var s = this.split('=');
    if (s[0]=="lang") default_lang = s[1];
});

// toplevel = earth
$("#earth").click(
    function(e) {
        e.preventDefault();
        //location.href = "http://www.geonames.org";
    }
);

// entry pointgeo_click($("#earth"));
}

And I bind that in the Polymer constructor:

<script>Polymer({
        is: "geo-dropdown",
        ready: geoready
    });
</script>

Post a Comment for "How To Make Onchange Event In Polymer"