0

I am using Spring4 and JSTL. The image shown below consist of elements that are dynamically created in a JSP page.

enter image description here

code in jsp page

<c:forEach var="themes" items="${Itemlist}"> <div class="col-lg-3 col-xs-6"> <!-- small box --> <div id="style" class="small-box bg-green" > <!--div contents --> </div> </div> </c:forEach> 

I need to change the div with id="style" class dynamically

small-box bg-red

small-box bg-blue

small-box bg-green

small-box bg-yellow ,all can change the box colour.How can i apply that dynamically.

Please help.

3
  • This shouldn't really be tagged with CSS as it's more of a question on how to reference a certain style than how to perform a given style; could lead a few people here with CSS knowledge who more than likely don't know anything about JSP Commented Jan 8, 2015 at 12:31
  • use if statement, and put logic in it. On what condition you want to change Commented Jan 8, 2015 at 12:31
  • @Jackhardcastle,@Sarz thanks for the reply.i have got the output as shown below. Commented Jan 9, 2015 at 6:35

2 Answers 2

2

You'll be simply solved by using <c:if> and varStatus .

<c:forEach var="themes" items="${Itemlist}" varStatus="status"> <div class="col-lg-3 col-xs-6"> <c:set var="color" value="green"/> <c:if test="${status.index == 1}"> <c:set var="color" value="red"/> </c:if> ... <div id="style" class="small-box ${color}" ></div> </div> </c:forEach> 
Sign up to request clarification or add additional context in comments.

Comments

-1

This is what i got Finally. @ko2ic

enter image description here

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.