0

Hello guys I search alot but find nothing regarding my problem. I have one foreach loop in that i have one anchor tag and that will be changed according to my ifelse condition. Now I want to change color of each if else condition in that. Please help me to do.My code is within jQuery script.

for(var j=0;j<arrayData.length;j++){
  var country = "";
  if(arrayData[j].key=="40"){
    country = "UK";
  }else if(arrayData[j].key=="41"){
    country = "INDIA";
  }else if(arrayData[j].key=="47"){
    country = "POLAND";
  }else{
    country = "GERMANY";
  }
  check+='<a class="btn btn-success" href="<?php echo base_url()?>uploads/'+arrayData[j].value+'">'+country+
                    '</a>|';
}
check +='</td></tr>';
1
  • you want to update the css of your <a> ? Commented Dec 9, 2017 at 7:33

1 Answer 1

1

You can just append it on the html string.

for(var j=0;j<arrayData.length;j++){
   var country = "";
   var color = "";
   if(arrayData[j].key=="40"){
       country = "UK";
       color = "red";
   }else if(arrayData[j].key=="41"){
       country = "INDIA";
       color = "orange";
   }else  if(arrayData[j].key=="47"){
       country = "POLAND";
       color = "yellow";
   }else{
        country = "GERMANY";
       color = "green";
   }

   check+='<a class="btn btn-success" style="background-color:' + color  + ';" href="<?php echo base_url()?>uploads/'+arrayData[j].value+'">'+country+
                    '</a>|';
}

 check +='</td></tr>';

Other option: You can also add class to <a> tag.

Like <a class="color-red">

CSS:

.color-red {
   background-color: red;
}
Sign up to request clarification or add additional context in comments.

2 Comments

thanks for your reply.Your code is working.But i want to change my anchor tags color. your code changes color of NAMES onto it
Ohh.. then we change the code from color to background-color. Please see my updated answer @amitsutar

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.