Sorry, I posted the wrong code........my code looked exactly like what you said but it did change the rendering of the table after I set the new value. Basically, what I have been trying to do was the following: - First I render the table and have a column heading cell that spans 4 columns - Then I click on the button which hides two of the columns - I want the table cell in the header row that originally spaned 4 columns to now only span 2 columns but I could not get it to work correctly. I did add some alert tags to redisplay the colspan attribute and it said it was changed from 4 to 2 but the header cell still spanned 4 columns.
I cheated and did it a way I do not like. In essence I built duplicate table header rows with one row containing colspan 2's and the other one with colspan 4's and then hide and show the apporpriate row. This is working fine but is done in a manner that would cause me to have to write custom code everytime I want to do this. I actually want to do it on multiple pages and there were multiple rows within the table where I needed to apply the same concept. Again, I was able to get it to work by coding each of the rows twice with the differetn attribute setting and controlling which ones show with the hide() and show() functions. I would like to figure out how to do this dynamically. Yes, I did eliminate the stupid getElementById code and use jQuery. I was in a hurry and basically copied the wrong code for the post. On Dec 17, 1:37 pm, Charlie Griefer <charlie.grie...@gmail.com> wrote: > I see where you're changing background colors, but where are you trying to > change colspans? > > untested, but > > $('myTDelement').attr('colspan', x); > > ... where 'x' is the numeric value, should work. > > also, it's criminal to use document.getElementById() within jQuery. > $('#element') is so much more elegant :) > > <script type="text/javascript"> > $(document).ready(function() { > $('#plusSign').click(function() { > $('.ba_toggle').toggle(); > > if $('#plusSign').html() == "+") { > $('#plusSign').html('-'); > $('th.ba_colspan, td.ba_colspan').each(function() { > $(this).attr('bgColor','red'); > }); > } else { > $('#plusSign').html('+'); > $('th.ba_colspan, td.ba_colspan').each(function() { > $(this).attr('bgColor','green'); > }); > } > > }); > }); > </script> > > > > > > On Thu, Dec 17, 2009 at 11:23 AM, davec <dcah...@hyphensolutions.com> wrote: > > I am trying to change the colspan attribute on some table cells when > > the user clicks on a button but it is not affecting the table. Perhaps > > someone can tell me what I am doing wrong. Here is my jQuery code: > > > <<script type="text/javascript"> > > $(document).ready(function() { > > $('#plusSign').click(function(){ > > $('.ba_toggle').toggle(); > > if(document.getElementById('plusSign').innerHTML=='+') > > { > > document.getElementById('plusSign').innerHTML='-'; > > $('th.ba_colspan, td.ba_colspan').each(function(){ > > $(this).attr('bgColor','red'); > > }); > > } > > else > > { > > document.getElementById('plusSign').innerHTML='+'; > > $('th.ba_colspan, td.ba_colspan').each(function(){ > > $(this).attr('bgColor','green'); > > }); > > } > > }); > > }); > > </script> > > -- > Charlie Grieferhttp://charlie.griefer.com/ > > I have failed as much as I have succeeded. But I love my life. I love my > wife. And I wish you my kind of success.- Hide quoted text - > > - Show quoted text -