treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Wrap around specific word with jQuery

  • I thought this would be easy but I am having trouble getting it, this is my HTML:

    <h2 class="dates">Sat Mar 31 2012</h2>


    Unfortunately, I don't have any control over this output, this is just the way it is. I want to wrap a around the date specifically so that I can style it with CSS, what would be the best way to do that? Please note, the date will change anywhere from the 1-31 so maybe all the dates would have to be in an array?

    Thank you in advance for your help.
  • Is the date already wrapped in an H2? Or are you sharing the desired result?

    Could you please share a bit more HTML. It might be possible to use the HTML around the date to target it specifically or at least focus in on it. I'm thinking a replace regex would work, so you wouldn't need an array of all dates.
  • How is the date being generated?
  • "How is the date being generated?"


    Something like:

    <div id='date'>
    <ul>
    <li><script type='text/javascript'>document.write(date_mmm);</script></li>
    <li><span class='day'><script type='text/javascript'>document.write(date_dd);</script></span></li>
    <li><script type='text/javascript'>document.write(date_yyyy);</script></li>
    </ul>
    </div>