IE setAttributeNode "onclick" with JavaScript

M

mowsen

Hey,

simple thing. I try to create a new button which holds a function as
"onclick" attribute.
I tried different ways, varried here and there but without success.
The function in question looks like:

<script type="text/javascript">

function createBt() {

var bt = document.createElement("input");
var attr_type = document.createAttribute("type");
var attr_value = document.createAttribute("value");
var attr_onclick = document.createAttribute("onclick");

attr_type.nodeValue = "button";
attr_value.nodeValue = "create element";
attr_onclick.nodeValue = "createBt()";

bt.setAttributeNode(attr_type);
bt.setAttributeNode(attr_value);
bt.setAttributeNode(attr_onclick);

document.getElementById("xx").appendChild(bt);

}

</script>


This works quite well within Firefox but IE has to be obstructive
again. Any suggestions?

Thanks,
Moka
 
M

mowsen

Hey,


got it already *cough* too tired to use google *cough* :/
the magic words are:


bt.onclick=function(){createBt();};


Moka
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,144
Latest member
KetoBaseReviews
Top