Forum Moderators: open

Message Too Old, No Replies

Add a dynamic div

Firefox extension related

         

kadnan

5:31 am on Jul 21, 2006 (gmt 0)

10+ Year Member



I am using following code to add a div from a firefox extension.

var bodyTag=window.content.document.getElementsByTagName("body")[0];

var bookmarkDiv=document.createElement("div");
bookmarkDiv.setAttribute("id","divHighlited1");
bookmarkDiv.setAttribute("style","position:absolute;top:5px;left:25px;height:20;width:20");
bodyTag.appendChild(bookmarkDiv);
var divHighlited=document.getElementById("divHighlited1");

but variable divHighlited keep returning null.

The above code does create a DIV with all attributes:


<div style="position: absolute; top: 5px; left: 25px;" id="divHighlited1"></div></body>

daveVk

7:54 am on Jul 21, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I note the result excludes height and width, should these be specified in pixels? Maybe ignores attributes after syntax error?

bookmarkDiv.setAttribute("style","position:absolute;top:5px;left:25px;height:20px;width:20px");

texmex

1:01 am on Jul 23, 2006 (gmt 0)

10+ Year Member



Where you have:
bookmarkDiv.setAttribute("id","divHighlited1");

Try instead:
bookmarkDiv.id="divHighlited1";