1

So i have a div that contains the text "12:00PM" .. it's a little clock application.

<div id="#clock">12:00PM</div>

I wanted to make the ":" part disappear and then reappear..

I wonder if this was possible w/ jQuery.

i have all the intervals and everything worked out... my clock gets updated.. but i just need a way to target/select that ":" character.. and remove it.. and then replace it :)

Is this possible without being too complicated?

Thanks

BoltClock
  • 665,005
  • 155
  • 1,345
  • 1,328
BrownChiLD
  • 3,215
  • 7
  • 41
  • 58

3 Answers3

2

Html:

<div id="#clock">12<span id="clock-colon">:</span>00PM</div>

jQuery:

$('#clock-colon').hide() // do what you want
Phil
  • 10,511
  • 17
  • 67
  • 97
2

DEMO

HTML is unchanged

CSS

.hidden {
    visibility:hidden;
}

jQuery

$clock = $("#clock");
$blink = true;
setInterval(function(){
    if ($blink) {
        $clock.html($clock.html().replace(":",'<span class="hidden">:</span>'));
        $blink = false;
    }
    else {
        $clock.html($clock.html().replace('<span class="hidden">:</span>',":"));
        $blink = true;
    }
}, 1000);
kei
  • 19,531
  • 2
  • 34
  • 59
1

If it's always going to be the same character, use the search() or indexOf() methods and then substring() and concatenation to eliminate the character.