0
votes

I'm trying to create a Firefox extension using the same html files I used to chrome extension. With some Google search, I found a way to use

xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
      xmlns="http://www.w3.org/1999/xhtml"

As namespace and to use the html file which I used in chrome as it is and its working fine. Now, I want to add elements dynamically into that html file using JavaScript. For example

var testdiv=document.getElementById('test');
var a = document.createElement('a');
a.setAttribute("innerText", "test");
testdiv.appendChild(a); 

But this is not giving the expected out put. Any suggestions on this or any other way to do this??

1
This is to add xul elements dynamically. I need to add html elements inside html doc which is a part of xul document.Hareesh

1 Answers

3
votes

If you want to create elements in a namespace, you have to use document.createElementNS method. So in your case, creating the A element would look like this:

var a = document.createElementNS('http://www.w3.org/1999/xhtml', 'a');