2

I set my css style inside jsp file. I added two "a link" and now i want to change spring:theme by any jQuery method from other file (js script).

Question: How to write function onClick() for my "a link" to change this spring:theme from different file?

JSP file

<head>
<c:choose>
<c:when test="">
</c:when>
<c:otherwise>
    <spring:theme code="standard.default.css.file" var="defaultCssFile" />
    <link type="text/css" rel="stylesheet"
        href="<c:url value="${defaultCssFile}" />" />
</c:otherwise>
</c:choose>
</head>



<div id="changeWrapper">
 <ul>
  <li><a href="#" class="change ch1" data-change2="firstCSS">a</a></li>
  <li><a href="#" class="change ch2" data-change2="secondCSS">b</a></li>
 </ul>
</div>

1 Answer 1

1

Add id to your <link> tag like the following:

<link type="text/css" rel="stylesheet" id="myId"
    href="<c:url value="${defaultCssFile}" />" />

By using the id attribute we can change the css file of the <link> dynamically.

Try the following:

$('#changeWrapper').on('click', '.change', function() {
    var obj = $(this), cssfile = obj.data('change2');
    $('#myId').attr('href', cssfile);
});
Sign up to request clarification or add additional context in comments.

2 Comments

Is any way to addClass() with new css to body (in this case) instead changing one css to second one ? Because in my second css file i change only color and font parameters...
@JacobRutka we can css rules at runtime, check Add Rules.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.