regex - Jquery Replace Second and Third Word -
im trying replace second , third word in html element.
so far can replace second word using this:
jquery("article#box-1 h2.join-box-head").each(function(i, v){ newhtml = jquery(this).html() .replace(/\s(.*?)\s/,'<span class="error">$1 </span>') jquery(this).html(newhtml); });
but im having hard time selecting third word too
html
<article id="box-1"> <h2 class="join-box-head">join family</h2> </article>
any ideas?
is regex needed?
jquery("article#box-1 h2.join-box-head").each(function(i, v){ var newhtml = jquery(this).html().split(" "); (var = 1; < 3; i++) newhtml[i] = '<span class="error">' + newhtml[i] + '</span>'; jquery(this).html(newhtml.join(" ")); });
or both in 1 span
jquery("article#box-1 h2.join-box-head").each(function(i, v){ var newhtml = jquery(this).html().split(" "); newhtml[1] = '<span class="error">' + newhtml[1]; newhtml[2] = newhtml[2] + '</span>'; jquery(this).html(newhtml.join(" ")); });
Comments
Post a Comment