-1

I am trying to prepend (i think thats the correct word to use) a "0" to the value of days in the screenshot here that are less than 10:

Screenshot of current class and item in question

I have the basic structure of the CSS to add the preceeding "0" value, but I just don't know how to add it ONLY IF the value is less than 10. As you can see I successfully added it to the entire class, but it also adds to the "11" value as well which I do not want.

Any help is VERY appreciated.

Michael

Yotam Omer
  • 15,310
  • 11
  • 62
  • 65
Michael G
  • 189
  • 10

2 Answers2

1

Rather do it with jquery

$(".target-div").each(function(){
 $(this).html(($(this).html<10?"0":"")+$(this).html());
});

Here .target-div is date div

void
  • 36,090
  • 8
  • 62
  • 107
1

If you can add some markup, then I would wrap the day with a span. Like so:

<div class="evo_date">
    <div class="start">
        <span>4</span>
        <em>Feb</em>
    </div>
</div>

And then run this jQuery snippet:

$(".evo_date .start span").each(function() {
    if ($(this).text().length == 1) {
        $(this).text("0" + $(this).text());
    }
});

Try it out here: http://jsfiddle.net/er0sh9bg/

curly_brackets
  • 5,491
  • 15
  • 58
  • 102
  • I tested your version our as well Kenneth and it works just as well. I appreciate you guys so much. Thanks for the fiddle as well. – Michael G Feb 10 '15 at 21:19
  • I'd love to upvote, but my reputation is currently too low, sorry! I will though. – Michael G Mar 11 '15 at 18:29