You could add an inline span
tag on a character.
$("p").html($("p").text().replace('@', '<span class="after">@</span>'));
Fiddle: http://jsfiddle.net/21jqbtv9/5/
If you'd like what's before or after a particular character, you should use lookahead
and lookbehinds
respectively.
lookbehind
: /(?<=@).+/
lookahead
: /.+(?=@)/
Change the first argument of the replace()
function to one of the above regex. Here is another example with a fiddle
$(document).ready(function() {
var email = $("p").html();
var emailParts = email.split('@');
var beforeText = emailParts[0];
var afterText = emailParts[2];
$("p").html($("p").html().replace(beforeText, "<span class='after'>" + beforeText + "</span>"));
});
http://jsfiddle.net/jL5kL72q/
For the part after the @
symbol, just change beforeText
to afterText
.
@" ? – dandavis Sep 29 '15 at 16:15