Snippets code from my daily experience

April 7, 2008

How to get element style values from XUL (or HTML)

Filed under: css,table2clipboard,xul — dafi @ 8:15 pm

I’m working to my Extend Firefox 2 Runner Up winner Table2Clipboard.

Many users tell me to add a simple feature, exclude cells having style display: none.

The solution is so straightforward that I could not believe after initial implementation.

You can style an element using CSS selectors

.invisible {
display: none;

<span id=“invisibleSpan” class=“invisible”>I’m invisible man</span>

or using the attribute style attribute

<span id=“invisibleSpan” style=“display : none”>I’m invisible man</span>

These two ways can both simply handled using getComputedStyle

var spanElement = document.getElementById(“invisibleSpan”);
var style = spanElement.ownerDocument.defaultView.getComputedStyle(spanElement, null);
var displayValue = style.getPropertyValue(“display”);

That’s all folks!!

Obviously you can use any CSS attribute not only display.

Pay attention to ownerDocument.defaultView, you should use window.getComputedStyle() but under XUL this doesn’t return what you expect.

getComputedStyle can be used in normal unprivileged HTML code, too.

getComputedStyle is a W3C standard and is present on Internet Explorer, Opera and Safari, too.

Little things make developer life easier.


March 30, 2008

XUL and textbox CSS styles

Filed under: -moz-appearance,css,xul — dafi @ 12:46 pm

If you want to change the background color for HTML input text boxes you simply set the background-color style attribute, very obvious.

.my-textbox {
background-color: red;

If you want to make same thing for XUL textboxes you apply the same style attribute discovering it doesn’t work… 😦

Ehm.. It works but you must disable standard mozilla behaviour using -moz-appearance attribute

.my-textbox {
-moz-appearance: none;
background-color: red;

Little lesson learned 😉

March 11, 2008

XBL, CSS selectors priority and Firefox 3

Filed under: css,firefox,gecko,mozilla,xbl,xul — dafi @ 8:58 pm

I wrote a little XBL component to allow menuitems to have images centered, I added it to Firefox 2 browser context menu and worked fine immediately, after a while I installed component on Firefox 3 beta 4 and surprisingly the menuitem didn’t show the image 😦

I’ve asked help on Mozilla IRC and after about an hour the mistery was revealed.

The innocent CSS declaration shown below works fine on Firefox 2

.menuitem-image-center {
-moz-binding: url(‘chrome://morekomodo/content/bindings/menu.xml#menuitemImageCenterBinding’);

but requires a little modification on Firefox 3 beta 5pre (at this time the latest available)

.menuitem-image-center {
-moz-binding: url(‘chrome://morekomodo/content/bindings/menu.xml#menuitemImageCenterBinding’)

You must notice the selector without !important attribute works on Firefox 3 when applied on menus different from browser context menu.

I suspect the browser context menu should have some special treatment on new Firefox…

Context menu

Create a free website or blog at