someclass

JSTL if-statement inside HTML attribute

Is it possible to do something like this in JSTL:

<div class="firstclass<c:if test='true'> someclass</c:if>"> <p>some other stuff...</p> </div> 

Is there a way to make this work, or is there a better way to add a class if you look at the JSTL-if statement?

+41
css jsp jstl jsp-tags
Oct 22 '09 at 10:55
source share
3 answers
 <c:if test='true'> <c:set value="someclass" var="cssClass"></c:set> </c:if> <div class="${cssClass}"> <p>some other stuff...</p> </div> 
+36
Oct 22 '09 at 11:03
source share

It is also possible to use the EL expression directly like this:

 <div class="${booleanExpr ? 'cssClass' : 'otherCssClass'}"> </div> 
+116
Oct 23 '09 at 10:37
source share

It works for me!

 <div id="loginById" style="height:<% out.print(instanceClass.booleanMethod()? "250px": "150px");%>"> 
-2
Sep 22 '17 at 15:17
source share



All Articles