1,105,380 Community Members

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

Member Avatar
lordrt
Posting Pro
510 posts since Jul 2010
Reputation Points: 20 [?]
Q&As Helped to Solve: 34 [?]
Skill Endorsements: 0 [?]
 
0
 

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">              
                <?php
                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?

Member Avatar
AleMonteiro
Master Poster
758 posts since Aug 2010
Reputation Points: 115 [?]
Q&As Helped to Solve: 143 [?]
Skill Endorsements: 29 [?]
 
2
 

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; ?> ">              
                <?php
                foreach($secondMenus as $secondMenu) {
Member Avatar
radhakrishna.p
Posting Whiz in Training
281 posts since Nov 2012
Reputation Points: 29 [?]
Q&As Helped to Solve: 64 [?]
Skill Endorsements: 11 [?]
 
0
 

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)
</div>   

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

thats it

Question Answered as of 1 Year Ago by AleMonteiro and radhakrishna.p
Member Avatar
lordrt
Posting Pro
510 posts since Jul 2010
Reputation Points: 20 [?]
Q&As Helped to Solve: 34 [?]
Skill Endorsements: 0 [?]
 
0
 

thanks, AleMonteiro's method is just what i needed

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