I have some elements like this:
<div class="box">
Team 1 - #5
</div>
<div class="box">
Team 2 - #3
</div>
And now I need to colorize these boxes like team 1 is getting blue and team 2 is getting red. But how can I do this?
Every Team is a member of a big clan which provides the color of the team. So I have a table with the clan color.
I'm using a MySQL table (two tables teams and clans). In the team table I have a foreign key field for the clan ID in the clan table
So that’s easy. If you have a table with your clan and its colors you have likely a field in your team table where the clan is written in with a foreign key right?
So your query should also get the color of the clan with an inner join.
so you can export the field of the clan color as class into your code like this:
<div class="box team-color-<?php echo $clan_color; ?>">
Team 1 - #3
</div>
And then you can set the color thing in CSS with ".team-color-[CLANCOLORVARIABLE] {}
"
But if you want to wrap your text with jQuery as asked you could do this:
So it would be perfect if you have your color as a classname in your elements. Then in jQuery you can do something like this:
$('.team-color-black').each(function() {
var content = $(this).text;
content.html('<span class="colorsetting">' + content + '</span>');
});
Then your text gets wrapped and can be formatted with css settings
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments