4
<td colspan="2" class="ai1ec-time">
    <a class="ai1ec-button ai1ec-calendar-link" href="#">
         Back to Calendar »                
    </a>
    July 12, 2012 @ 08:00 am – July 13, 2012 @ 10:00 pm
</td>​

Above is my HTML markup which display the text below.

Back to Calendar » July 12, 2012 @ 08:00 am – July 13, 2012 @ 10:00 pm ​

I need to remove @ 08:00 am from the starting date/time and @ 10:00 pm from the ending date/time. How can this be done with jQuery? I heard and read of something called Regexp, is that what needs to be used? With jQuery remove()?

I forgot to mention that the 'time' is not fixed. The only thing that's fixed is that the portion that needs to be removed starts with '@' and ends with 'm'

4
  • Will the parts being removed always be "@ 08:00 am" and "@ 10:00 pm"? Commented May 5, 2012 at 7:52
  • Nope. The time will vary. But it will always start with @ Commented May 5, 2012 at 7:55
  • Is it possible to alter the html in anyway, wrapping elements in spans, or using data attributes to make targeting easier? Commented May 5, 2012 at 7:56
  • Unfortunately no :( I checked out the PHP function that returns the value. It's all bundled together and I have no idea how to edit it Commented May 5, 2012 at 7:58

3 Answers 3

4
$(".ai1ec-time").html(function(i,o){
  return o.replace( /@[0-9:\s]+(am|pm)/ig, '' );
});

Demo: http://jsbin.com/ozuwob/2/edit

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks Jonathan! Let me try this now
@IwaniKhalid Did you have any luck?
jsfiddle.net/pLAnd/1 Unfortunately no, on jsfiddle. Wonder if it's the rendering engine
I tested it on the live site and it works! Yay! Thank you Jonathan
1
var $td = $('td.ai1ec-time')
$td.html($td.html().replace(/@ \d{1,2}:\d{2} [ap]m/g, ''))

4 Comments

Am I doing something wrong here? Doesn't seem to be working jsfiddle.net/mTpCn/2
javascript variables don't start with a $ as far as i know
I managed to get it working with Jonathan's answer! Thanks guys for the help!
reason was in table layout. You had to not omit <table> and <tr> tags
1

first make sure you have jQuery running ( jQuery )

Then use something like this:

$(".ai1ec-time").html(function(i,o){
  return o.replace( /\@\s\d\d\:\d\d\s(am|pm)/ig, '' );
});

demo: js bin

4 Comments

Yeah, its not only 8am and 10am. That's the tough bit for me
It would not work cause you are passing string instead of regexp, and AFAIK .replace() does not change caller-string, it only returns new string. So you must make smth like obj.html(obj.html().replace())
Thanks @scubaFLY and caligula for your time and answers. Appreciate it so much :)
check out @Jonathan Sampson answer that one is working. also updated mine so it works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.