Setting opacity/transparency on elements using JavaScript

Here’s a short snippet to set the opacity of an element: function setOpacity(e,opacity){ var; o.opacity=(opacity/100); //Opera o.MozOpacity=(opacity/100); //Mozilla+Firefox o.KhtmlOpacity=(opacity/100); //Konqueror o.filter=”alpha(opacity=”+opacity+”)”; //IE } Use it like this: var e=document.getElementById(‘myElement’); setOpacity(e, 50);//Sets the opacity to 50% [tags]JavaScript[/tags]

Cross browser DynamicSelect JavaScript class

When developing web applications, select-boxes are usually involved in the UI. I’ve put together a custom JavaScript class to handle things like removing, adding and selecting elements. By the way, Matt Kruse has a bunch of nice JavaScript libraries! Example: var e=new DynamicSelect(‘MySelect’); e.removeAll(); e.append(‘Entry 1’,”); e.append(‘Entry 2’,”); e.selectAll(); e.unselectAll();‘Entry 2’); e.toggleAll(); if(e.contains(‘Entry 1’)){ […]

Replacing No documents found

This has been done before. Here is my contribution: /** * Replaces \”No Documents Found\” with a custom text. * * @author Johan Känngård, * @param message the text to replace with * */ function replaceNoDocumentsFound(message){ var h2=document.getElementsByTagName(\’h2\’); if(h2!=\’undefined\’&&h2.length>0&&h2[0]!=\’undefined\’) { var oldTextNode=h2[0].firstChild; var newTextNode=document.createTextNode(message); h2[0].replaceChild(newTextNode,oldTextNode); } } Put the function in the HTML Head […]

Venkman – JavaScript debugger extension for Firefox

Via Tom, I found Jim Andertons blog, which mentions Venkman. It is a JavaScript debugger, that can be used to find those irritating small typos and bugs (not written by me of course ;-). It seems to be a jewel, and I will probably use it when I’m back from vacation!

Remove an element in a JavaScript Array

If you know the index of the element to remove, you could use the splice method, like this: var a=[‘one’,’two’,’three’,’four’]; a.splice(1,1); // Removes 1 element from index 1 alert(a); // Results in ‘one’,’three’,’four’ If you don’t know the index, but the value of the element, you could add a little method to the Array class […]