Jump to content

Setting className with javascript not working on hover


Darghon

Recommended Posts

Hi, I'm building a table with javascript, and i'd like to add a class to the cells,

Adding the class itself works, but if I add an css even like :hover, it refuses to work

 

is there any way to get this to work, without adding onmouseover and onmouseoff events to the cell?

 

The style I want to call is =>

<style>
.myClass:hover{
	background-color:#00cc00;
	border:0px;
	filter:alpha(opacity=25);
	-moz-opacity:.25;
	opacity:.25;
}
</style>

the code building the table is:

var table = document.createElement("table");
	table.style.borderCollapse="collapse";
	var rows = 15; //is loaded from an xml
	var cols = 15; //is loaded from an xml
	for(var i = 0;i < rows;i++){
		var row = table.appendChild(document.createElement("tr"));
		for(var j = 0;j < cols;j++){
			var cell = row.appendChild(document.createElement("td"));
			cell.style.width = "32px";
			cell.style.height = "32px";
			cell.style.margin = "0px";
			cell.style.padding = "0px";
			cell.title = "("+(i+1)+", "+(j+1)+")";
			cell.className = "myClass";
		}
	}

 

what should I do

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.