fee Posted May 27, 2006 Share Posted May 27, 2006 What I do is clear my table with (excluding the header): while(table.rows.length>1) { table.deleteRow(1) } and then I want to add some new rows with cells by: var material = x.insertCell(0)var rodzaj = x.insertCell(1)var ilosc = x.insertCell(2)material.innerHTML = "jeden"rodzaj.innerHTML = "dwa"ilosc.innerHTML = "trzy" I wonder if i can set class="someclassname" for new cells using DOM properties? Or is there other way/trick to do it? Link to comment Share on other sites More sharing options...
adservio Posted May 27, 2006 Share Posted May 27, 2006 You can assign a class by using className: <style type="text/css">.no_tint { background-color: #fff;}.tint { background-color: #6ff;}</style><script type="text/javascript">var i = 0;function insRow(){var c;((++i) % 2 == 0 )? c = 'no_tint' : c = 'tint'; var x=document.getElementById('myTable').insertRow(0);x.className = c;var y=x.insertCell(0);var z=x.insertCell(1);y.innerHTML="NEW CELL1";z.innerHTML="NEW CELL2";}</script> Used with this page. Link to comment Share on other sites More sharing options...
fee Posted May 27, 2006 Author Share Posted May 27, 2006 You can assign a class by using className:Thanks - it works! But why there is nothing about it at w3schools then? Link to comment Share on other sites More sharing options...
adservio Posted May 27, 2006 Share Posted May 27, 2006 I don't know that any one "web space" can contain everything, too much info, not enough time.... Here's a reference:http://www.javascriptkit.com/domref/elementproperties.shtml Link to comment Share on other sites More sharing options...
Webworldx Posted May 27, 2006 Share Posted May 27, 2006 I don't know if className is considered as standard [w3]. It's kind of a grey area in my opinion on whether support for getAttribute('class') is the correct method of access (mozilla supports getAttribute('class') whereas IE supports getAttribute('className'), .className is universal). I can see why MSIE decided against it originally (conversions from languages like Perl), but I do think it should be fixed in the next JS verison - although I didn't see it in Brendan's proposals at his latest conference... Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now