?
Solved

Setting the colspan attribute of a "th" cell dynamically

Posted on 2007-04-09
3
Medium Priority
?
786 Views
Last Modified: 2012-08-13
Hi,

I am dynamically adding rows to an HTML table and one of them is a "th" row. I wanted to set the "colspan" attribute for this dynamically and am not able to do so - for some reason the code below does everything except increase the colspan of the row. My code is below. Please help.

      var tBody = document.getElementById("Agenda").getElementsByTagName("tBody")[0];
      var tRowH = document.createElement("tr");
      var tHead = document.createElement("th");
      tHead.setAttribute("colspan","2");
      tHead.setAttribute("bgcolor","#cccc99");
      tHead.setAttribute("align","center");
      tHead.innerHTML = "Topic 3";      
      tBody.appendChild(tRowH);
Thanks,
Aruna
0
Comment
Question by:arunatata
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 3

Expert Comment

by:mtorre615
ID: 18879598
try tHead.colSpan = 2.
0
 
LVL 15

Expert Comment

by:stanscott2
ID: 18879682
There's a quirk to this one.  Use appendChild to attach the TH to the TR tag first, and THEN set the colSpan attribute.
0
 
LVL 8

Accepted Solution

by:
jawahar_prasad earned 2000 total points
ID: 18880913
Hi.. Aruna,
TRY THIS.. Some modifications to your code...

     var tBody = document.getElementById("Agenda").getElementsByTagName("tBody")[0];
      var tRowH = document.createElement("tr");
      var tHead = document.createElement("th");
      tHead.setAttribute("colSpan","2");
      tHead.setAttribute("bgColor","#cccc99");
      tHead.setAttribute("align","center");
      tHead.innerHTML = "Topic 3";      
      tBody.appendChild(tRowH);

EXPLANATION:
Colspan should be "colSpan" and not "colspan"    //CASE SENSITIVE
bgcolor should be "bgColor" and not "bgcolor"      //CASE SENSITIVE

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question