javascript - Prototype JS: Document.observe fires "undefined is not a function" error -
i try use event.observe method provided prototype js. sure dom loaded, use document.observe. causes error uncaught typeerror: undefined not function. prototype js loaded can see below:
html
<!doctype html> <html> <head> <title>playground</title> <script language="javascript" type="text/javascript" src="../js/prototype.js"></script> <script language="javascript" type="text/javascript" src="../js/functions.js"></script> </head> <body> <div> <a href="#" id="meinlink">hello world</a> </div> <input type="button" onclick="changelinktext()" value="change link using prototype"> </body>
javascript
//this works var changelinktext = function(){ $("meinlink").innerhtml="prototypeworks"; }; //this causes error document.observe("dom:loaded", function() { $("meinlink").observe('click', function(e) { document.getelementbyid('meinlink').innerhtml="prototypedoesntwork"; }); });
your d
in
document.observe("dom:loaded", function() {
is upper-case, fixing it's correct notation
document.observe("dom:loaded", function() {
will job.
you can try invoke on-click-event listener.
$$('meinlink').invoke('on', 'click', '.item', function(event, el) { // el 'meinlink' element });
it's possible using on job.
$("meinlink").on("click", function(event) { document.getelementbyid('meinlink').innerhtml="prototypedoesntwork"; });
Comments
Post a Comment