0

I have a list with the following markup:

<ul class="meta meta-event">
    <li>September 4 @ 10:00 am - 5:00 pm</li>
    <li>Some Hotel, London</li>
</ul>

But I'd like to insert a <br /> tag before the '@' character (I need to do this in jQuery due to it being a WP plugin with little customisation optons)

Does anyone know how I can do it?

2
  • $('.meta-event li:contains("@")').html(function(i,html){ return html.replace(/@/, '<br />@') }) Commented Aug 14, 2014 at 14:44
  • is it always the same li the first li? Commented Aug 14, 2014 at 14:44

1 Answer 1

2

You can use jQuery's html() method, and a string replace to insert the <br> tag before the @

$('.meta-event li:contains(@)').html(function(_, html) {
    return html.replace(/@/g, '<br />@');
});

FIDDLE

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

Comments

Your Answer

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