Reputation: 3733
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
Upvotes: 1
Views: 281
Reputation: 20521
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);
Upvotes: 2
Reputation:
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.
Upvotes: 1
Reputation: 11175
Html:
<div id="#clock">12<span id="clock-colon">:</span>00PM</div>
jQuery:
$('#clock-colon').hide() // do what you want
Upvotes: 2