Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change the class of the tr element dynamically

Status
Not open for further replies.

bean1234

Technical User
Nov 14, 2006
45
US

Hello Expets,

I am applying the following cs to teh table rows and tds which are under a table with class name "subparent"

Code:
.subparent tr.subhidden td  {

         padding:3px 0px 3px 10px;background-color:#ffffff;display: none;
}

.subparent tr.subshow td {
     padding:3px 0px 3px 10px;background-color:#ffffff;display: block;
     
}

I dynamically chnage the className using the following javascript code

Code:
function toggleit(parentDiv,imageElement,imgName1,imgName2){

 var temp = parentDiv.nextSibling
 //parent div is actually the tr above the tr I am trying to chnage the className of.
 //temp is the tr of teh table
 
 
 
 if(temp.className == "subhidden"){
  
  alert('Equal to subhidden');
  temp.className = "subshow";
  alert('Changed to '+temp.className)
  
  }
  
  else{

  alert('Equal to subshow');
  temp.className = "subhidden";
  alert('Changed to '+temp.className)

  
  }
  
  
  imageElement.src=(imageElement.src.indexOf(imgName1) == -1) ?imgName1:imgName2;
  parentDiv.focus();

 }

Everything works fine if I start from "subshow" as the initial class of the tr the tr is displayed initially and hidden on click, howoever if I start from "subhidden" class for the tr and it is hidden and never goes back to show to tr again even though I have confirmed that the the className chnages to "subshow", can you please let me know what the problem might be?

Thanks.
 


I was able to hide but I am not able to show it back even if I use the display:block. Thanks.
 

I mean even if I use "display:table-cell" I am still not able to show it back.
 
It's because through your style sheet you've defined the style of the TD. You're toggling the display of the row, but the display of the TD is still set to 'none'.

Change your style sheet to this:
Code:
.subparent tr td {

     padding:3px 0px 3px 10px;background-color:#ffffff;
}

.subparent tr.subshow{
     display: block;

}

.subparent tr.subhidden{
	display: none;
}

Adam
 
Hey Adam, it's been a while!

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
 
Going by that formula, it proves that I really hate my job [lol]

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top