Connecting Tech Pros Worldwide Forums | Help | Site Map

Change CSS(Class attribute to other attribute)

Member
 
Join Date: Sep 2006
Posts: 73
#1: Nov 6 '08
I have surf throught many site and found this...
[HTML]http://www.adobe.com/go/gn_home[/HTML]
how to change an element attribute to other class attribute...
I wonder......can we change class attribute to something else..
i need to change class that have[code].DisplayBlock {
display : block;
}
CODE] to
Expand|Select|Wrap|Line Numbers
  1.  .DisplayNone {
  2.       display: none;
  3.      }
  4.  
by vbscript or javascript for some function that i need

DrBunchman's Avatar
Moderator
 
Join Date: Jan 2008
Location: Winchester, UK
Posts: 930
#2: Nov 6 '08

re: Change CSS(Class attribute to other attribute)


Hi MATTXtwo,

You can use Javascript to do this, like so:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3.     <style>
  4.         .DisplayBlock {
  5.               display : block;
  6.             }
  7.  
  8.         .DisplayNone {
  9.               display: none;
  10.              }
  11.  
  12.     </style>
  13.     <script type="text/javascript">
  14.         function Hide(element)
  15.         {
  16.         document.getElementById(element).className = 'DisplayNone';
  17.         }
  18.         function Show(element)
  19.         {
  20.         document.getElementById(element).className = 'DisplayBlock';
  21.         }
  22.     </script>
  23. </head>
  24. <body>
  25.     <div id="div1" class="DisplayBlock" OnMouseOver="Hide('div1')" OnMouseOut="Show('div1')">
  26.         Hello World!
  27.     </div>
  28. </body>
  29. </html>
Let me know if this helps,

Dr B
Member
 
Join Date: Sep 2006
Posts: 73
#3: Nov 6 '08

re: Change CSS(Class attribute to other attribute)


Quote:

Originally Posted by DrBunchman

Hi MATTXtwo,

Let me know if this helps,

Dr B

Sorry Dr B
Expand|Select|Wrap|Line Numbers
  1. function changeBMBI(vtype)
  2. {    var x=1;
  3. //var set as many of label element that need to be control
  4.     if(vtype=="BM")
  5.     {    
  6.         document.getElementById("BI"+x).style.display="none";
  7.         document.getElementById("BM").style.display="none";
  8.         document.getElementById("BM"+x).style.display="block";
  9.         document.getElementById("BI").style.display="block";
  10.         alert(vtype=="BM"+"bm");
  11.     }else{
  12.     alert(vtype=="BM"+"not"+vtype);
  13.     }
  14.     if(vtype=="BI")
  15.     {    document.getElementById("BM"+x).style.display="none";
  16.         document.getElementById("BI").style.display="none";
  17.         document.getElementById("BI"+x).style.display="block";
  18.         document.getElementById("BM").style.display="block";
  19.         alert(vtype=="BI"+"bi");
  20.     }else{
  21.     alert(vtype=="BI"+"not"+vtype);
  22.     }
  23. }
  24. ..................................................................................................................
  25. <label id="BM1"><b>Bahagian Sumber Manusia</b></label>
  26. <label id="BI1"><b>Human Resource Department</b></label></font></td>
  27. </tr><tr><td align="right">
  28. <label id="BI" onclick="javascript: changeBMBI('BI')">versi Bahasa Inggeris</label>
  29. <label id="BM" onclick="javascript: changeBMBI('BM')"><b>Malay version</b></label></td>
  30. </tr><tr><td><input id="versions" type="hidden" value="<%=session("versiBMBI")%>"><%Response.Write session("versiBMBI")%></td>
  31.  
it's for changing between to language ..
The thing is we can only change the style by element not by class declare on all element or div id's for bulk element change from style display block to style display none
DrBunchman's Avatar
Moderator
 
Join Date: Jan 2008
Location: Winchester, UK
Posts: 930
#4: Nov 6 '08

re: Change CSS(Class attribute to other attribute)


Sorry MATTXtwo, I don't understand what it is your trying to do or why the example I gave above won't work.

I thought that you wanted to be able to change the class of an element programatically - was I wrong?

Dr B
Member
 
Join Date: Sep 2006
Posts: 73
#5: Nov 7 '08

re: Change CSS(Class attribute to other attribute)


Quote:

Originally Posted by DrBunchman

Sorry MATTXtwo, I don't understand what it is your trying to do or why the example I gave above won't work.

I thought that you wanted to be able to change the class of an element programatically - was I wrong?

Dr B

it works fine....it just I thought it would be done like change the class definiton from style:display block to style:display none..
so i added the x var as for the id like BM,BM1,BM2 and so on
Thanks anyway
DrBunchman's Avatar
Moderator
 
Join Date: Jan 2008
Location: Winchester, UK
Posts: 930
#6: Nov 7 '08

re: Change CSS(Class attribute to other attribute)


Ah I see! I don't think that's possible using javascript but if any other experts know different then please let us know.

I'm glad that it works for you anyway :-)

Dr B
Reply