help: add background color to div if specific item is found


Hello, anyone can help me to add a background color to my div, for example, if an id of 2 is found (pls see my code)

$idMenuParent = $resGetInfoMenu[0]['IDMENUPARENT'];
        //if the menu has a parent
        if($idMenuParent) {
            // get menu info
            $infoMenuParent = cGetInfoMenu($idMenuParent);
            //fetch all child menus
            $secondMenus = cGetMenus($_SESSION['IDLANG'], 1, $idMenuParent);

            if(!empty($secondMenus)) {
                <div id="secondary-menu-main">

                <div id="secondary-menu-items">              
                foreach($secondMenus as $secondMenu) {
                    //get child menu info
                    $sousItem = cGetItemMenu($_SESSION['IDLANG'], $secondMenu['IDMENU']);
                    if($idMenuSelected == $secondMenu['IDMENU']) {
                        $selected = "-activated";
                    else {
                        $selected = "";

where i want to check the value of the variable $idMenuParent , and if it has for example value 2, to get the
div id="secondary-menu-items" background as blue in color, else any other value should return gray color.

Anyone can help me solve this issue?

Featured Replies in this Discussion


I think it could be something like this:

if(!empty($secondMenus)) {

    $backgroundColor = $idMenuParent == 2 ? 'blue' : 'gray';


                <div id="secondary-menu-main">

                <div id="secondary-menu-items" style="background-color: <?php echo $backgroundColor; ?> ">              
                foreach($secondMenus as $secondMenu) {

we can add background color to div by using style property of div tag as shown bellow

<div id="your_id_value" style="background-color: grey">  
// you may give color name directly or its rgb value like (#FFCCEE)

based on your condition you may add style property for the particular div tag

thats it

Question Answered as of 2 Years Ago by AleMonteiro and radhakrishna.p

thanks, AleMonteiro's method is just what i needed

Isn't it about time forums rewarded their contributors?

Earn rewards points for helping others. Gain kudos. Cash out. Get better answers yourself.

It's as simple as contributing editorial or replying to discussions labeled or OP Kudos

This question has already been solved: Start a new discussion instead
Start New Discussion
Tags Related to this Article