469,320 Members | 2,115 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,320 developers. It's quick & easy.

How would I go about dynamically adding the <span> tags as innerHTML?

shelzmike
I have a issue, which I am thinking might not be that difficult.

How would I go about dynamically adding the <span> tags as innerHTML (and consequently replacing what is currently in each cell) before the visibility changes.

Seems to be I would first have to collect all of the nodeValues first, then loop through each cell and add an innerHTML of essentially this: '<span>' + nodeValues[i] + <'\span>

Now, I am aware that this is not proper syntax, I am merely illustrating a point. But is this logical and possible?

Mike
Oct 12 '11 #1
3 1655
Answered my own question - it was actually pretty easy.

Expand|Select|Wrap|Line Numbers
  1. function hideRawData() {
  2.     var tbl = document.getElementById("users_table");
  3.     var tblRows = tbl.getElementsByTagName("tr");
  4.     var rawData = tbl.getElementsByTagName("td");
  5.  
  6.     for (k=0; k < rawData.length; k++){
  7.         //alert(rawData[k].firstChild.nodeValue);
  8.         rawData[k].innerHTML = "<span>" + rawData[k].firstChild.nodeValue + "</\span>";
  9.     }
  10.  
  11.     for(j = 0; j < rawData.length; j++) {
  12.         //rawData[j].style.display = "none";
  13.         rawData[j].firstChild.style.visibility = "hidden";
  14.     }
  15.  
  16.    // alert ("Raw data has been hidden")        
  17. } // end hideRawData
Oct 12 '11 #2
Dormilich
8,651 Expert Mod 8TB
note: HTML does not use backslashes, i.e. "</\span>" should be "</span>" (\s is a RegExp for whitespace)
Oct 13 '11 #3
Yeah, I didn't mean to do that. Luckily it still worked, but I have since fixed it. Thanks!

Mike
Oct 13 '11 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Aaron Ackerman | last post: by
10 posts views Thread by David | last post: by
11 posts views Thread by Steven D'Aprano | last post: by
3 posts views Thread by Ben Dewey | last post: by
1 post views Thread by Tor Inge Rislaa | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Gurmeet2796 | last post: by
reply views Thread by mdpf | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.