0

I got a requirement in which user should be able to change css of masterpage dynamically in sharpoint site. One way I found is to read the content of master page, replace the css classes, so that the new class will be applied.But this does not suits my requirements as it changes the actual class name.

is there any other way to achieve this? How can I dynamically change css of master page?

Thanks

0

To can also use Jquery/Javascript for this

document.getElementById("MyElement").className = "MyClass";

What you can do is put runat="server" tag to the element and create master page code behind class. and change the class name from code behind.

To add master page code behind you can refer: http://blog.nerdery.com/2013/04/tech-tips-creating-a-sharepoint-2010-master-page-with-code-behind/

  • But I don't want to change the master page or css file. I just want to replace the existing classname with new class name. – Priya Sep 12 '14 at 6:16
  • You want to change the class name for a specific element? – Aanchal Sep 12 '14 at 6:17
  • Yes, I want to change the css class name for specific element. For example suitbar. – Priya Sep 12 '14 at 6:29
  • So what you can do is put runat="server" tag to the element and create master page code behind class. and change the class name from code behind. – Aanchal Sep 12 '14 at 6:31
  • Can't we access it from user control which I load on masterpage? – Priya Sep 12 '14 at 6:33
0

1) you can check the conditions or directly change the classes through user control using below c# code:

 if (condition)

    div.Attributes["class"] = "newClass";

2) using Jquery you can use the below code:

  $('div').removeClass("currentClass").addClass('newClass');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.