简体   繁体   中英

Wrapp link in strong with replace()

I would like make a strong tag around my links in a div. These links appear dynamically.

I tried to do this :

$('#alertWrapp').each(function() {
  $(this).html($(this).text()
    .replace(/#[a-z0-1A-Z]+/g, '<span style="color: #ed6567;">$&</span>')
    .replace('http://', '<strong>$&</strong>')
  );
});

But I can't continue the regex, it's too much complex... So it can be possible to build a regex who find the http:// protocole to space ? because it's a space who set the end of my links...

Thanks you

Why dont you just style the anchor. Check this fiddle

a {
font-weight: bolder;
}

OR

If its the url text that you want to be wrapped in bold try the following or check this fiddle

var text = data.replace(/https?:\/\/[^ ]+/g, '<strong>$&</strong>')

To replace http://[anything-until-space] or https://[anything] try this

$('#alertWrapp').each(function() {
    $(this).html(
        $(this).text()
        .replace(/#[a-z0-1A-Z]+/g, '<span style="color: #ed6567;">$&</span>')
        .replace(/https?:\/\/[^ ]+/g, '<strong>$&</strong>')
    );
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM