P
Pim
Hi,
I can't make this code work on *this* web client:
Mozilla/5.0 (X11; U; Linux i686; fr; rv:1.9.0.13) Gecko/2009082121
Iceweasel/3.0.6 (Debian-3.0.6-1)
I want to add a 'click' event to an elem of this kind:
<div id="xx">taratata</div>, but this element is not
in the HTML file : it is "DOM created".
Here's what my code tries to do:
//Creating a <div id=fs>[< Agrandir >]</div>
var anewdiv = document.createElement('div');
anewdiv.id='fs';
anewdiv.innerHTML="[< Agrandir >]";
//Now inserting the Event handler on this div
var evType = 'click';
if (anewdiv.addEventListener){//Mozilla ¿ firefox ¿
alert("Mozilla");
anewdiv.addEventListener(evType, function() {alert("TEST!"); } , false);
return true;
}
else if (anewdiv.attachEvent){//IE
alert("IE");
var r =
anewdiv.addEventListerner( "on" + evType, function() { alert("TEST!");});
return r;
}
else {
alert("Impossible de brancher un gestionaire d'évènements");
return false;//branchement impossible
}
#Inserting element to the html page
var beforeElement = document.getElementById("topmenu");
var theParent = beforeElement.parentNode;
theParent.insertBefore(anewdiv, beforeElement);
The script works with IE (not it's not exactly this code for IE).
Firefox reports none errors and event handler seams to be inserted
,but when i click on the div area : nothing happens.
I cannot see errors in JS logs neithers.
Where dit i misstake?
Who can help me?
Thank's very much in advance.
I can't make this code work on *this* web client:
Mozilla/5.0 (X11; U; Linux i686; fr; rv:1.9.0.13) Gecko/2009082121
Iceweasel/3.0.6 (Debian-3.0.6-1)
I want to add a 'click' event to an elem of this kind:
<div id="xx">taratata</div>, but this element is not
in the HTML file : it is "DOM created".
Here's what my code tries to do:
//Creating a <div id=fs>[< Agrandir >]</div>
var anewdiv = document.createElement('div');
anewdiv.id='fs';
anewdiv.innerHTML="[< Agrandir >]";
//Now inserting the Event handler on this div
var evType = 'click';
if (anewdiv.addEventListener){//Mozilla ¿ firefox ¿
alert("Mozilla");
anewdiv.addEventListener(evType, function() {alert("TEST!"); } , false);
return true;
}
else if (anewdiv.attachEvent){//IE
alert("IE");
var r =
anewdiv.addEventListerner( "on" + evType, function() { alert("TEST!");});
return r;
}
else {
alert("Impossible de brancher un gestionaire d'évènements");
return false;//branchement impossible
}
#Inserting element to the html page
var beforeElement = document.getElementById("topmenu");
var theParent = beforeElement.parentNode;
theParent.insertBefore(anewdiv, beforeElement);
The script works with IE (not it's not exactly this code for IE).
Firefox reports none errors and event handler seams to be inserted
,but when i click on the div area : nothing happens.
I cannot see errors in JS logs neithers.
Where dit i misstake?
Who can help me?
Thank's very much in advance.