Michael
Michael

Reputation: 35

How do I change a box that has text in so it only has colour in?

I am currently making a connect four game, I have been advised to use some existing code that I have previously used on a noughts and crosses game.

The problem I have is trying to change the noughts and crosses into colours. The code I currently have is ( http://pastebin.com/AkCBLnmt ). I am wanting to change x to green and o to red.

I have tried the following but it didn't work:

$(this).colour("Red");

$(this).colour("Green");

Could someone please advise me how to change the text ( x & o) to colours red and green.

Thanks

Upvotes: 0

Views: 49

Answers (5)

MakeLoveNotWar
MakeLoveNotWar

Reputation: 954

Something like this?

$('.colours').each(function(){
 if($(this).text() == 'x') {
  $(this).css('color','green');
 }else{
  $(this).css('color','red');
 }
});

Upvotes: 0

scottdurban
scottdurban

Reputation: 518

Try this

 $(this).css({'color','red'});

Remember, that code (generally) prefers Americanised spelling.

If this doesn't work for you, could you post the accompanying HTML?

Upvotes: 1

Johannes Geidel
Johannes Geidel

Reputation: 126

If you want to change the background color

$(this).css('background-color', 'red');

If you want to change the text color

$(this).css('color', 'red');

Upvotes: 0

Stefan
Stefan

Reputation: 1

Use jquery.css() to change your style as follows:

$(this).css({'color':'red'});
$(this).css({'color':'green'});

For more style U want to change,U can use

$(this).css({'color':'red','display':'block','margin':'10px'});...

Upvotes: 0

Dhara Parmar
Dhara Parmar

Reputation: 8101

You can try this to change color of text:

$(this).css("color","red");

Upvotes: 0

Related Questions