views:

39

answers:

2

I have a simple if statement in my view that returns x = 0 or 1. Based on this simple result, I want to change the styling of the div that contains the entire section.

<div>
  conditional that returns x=1 vs x=0 (and a few displayed items)
  based on this loop, restyle the div
</div>

Let's say, if x = 1, I want to make background-color:rgb(210,215,220);

How can I accomplish this? I am not experienced with Javascript but I'm sure any code required would be very simple. Thank you!

A: 

<script>

if(x==1)

{

$("#divid").css("background-color","rgb(210,215,220)");

}

</script>

include jquery, and give the div an id of divid

:)

Pete Herbert Penito
+1  A: 

Add an ID to your DIV like:

<div ID="colorThis">
  conditional that returns x=1 vs x=0 (and a few displayed items)
  based on this loop, restyle the div
</div>

Then do this:

if(x==1)
{
  ​document.getElement​ById('colorThis').style.background = 'rgb(210,215,220)'​​​​;​​​​​​​​​​​​​​
}
Gary