Click here to Skip to main content
15,881,715 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
function ShowDescription(id,spanid) {
       document.getElementById('discription').innerHTML = id.innerHTML;
     
   }



XML
<ul id='tabs'>
    <li><a href='javascript:ShowDescription(divCourse3,span1);'><span id='span1' class='first focus'>
        Overview</span></a></li>
    <li><a href='javascript:ShowDescription(divCourse4,span2);'><span id='span2' class='last'>
        Curriculum</span> </a></li>
</ul>



My requirement is that when user click on function spanID is passed in paremeter to function, so here i need to change the css class of finction using javascript. so if anyone knows how to do that plz help me

Thanks in advance
Posted

We can easily change the css class of an element using javascript. I am not sure that what do you mean by "change the css class of finction ".

You can change the css class of any element as

To replace all existing classes with one or more new classes, set the className attribute:
SQL
document.getElementById("MyElement").className = "MyClass";


To add an additional class to an element:

To add a class to an element, without removing/affecting existing values, append a space and the new classname, like so:
SQL
document.getElementById("MyElement").className += " MyClass";



Let me know if this resolves your problem
 
Share this answer
 
Comments
thatraja 7-Oct-13 3:33am    
Right, 5!

Hey you Brij! long time no see...
Brij 7-Oct-13 3:38am    
Yes!! got busy on other priorities.. answer in forums when get a chance :)
function ShowDescription(id,spanid) {
var elm = document.getElementById(spanid);
elm.removeAttribute("class");
elm.setAttribute("class","newClass");

}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900