In a website, is there any way of changing text attribute of keyword, like product name, in an entire website without using any kind of html tags wrapped around those instances? I may require to define those keywords in server side environment or there may be a server side script in which I may need to define. Or can we use client side Javascript like some jquery plugin?
Asked
Active
Viewed 85 times
1 Answers
0
You can use Javascript on the client side to achieve this.
Drawing from this answer the following is a simple example:
JS:
$('*').contents().each(function(){
if(this.nodeType === 3) {
$(this).replaceWith(this.wholeText.replace(/target/g, 'replaced'));
}
});
HTML:
<h1>target</h1>
<p>Here it is: <span>target</span> and target</p>
-
Yes, that solved my problem. I can add span tag with some css class through this replace function. $(this).replaceWith(this.wholeText.replace(/target/g, 'Target')); I was exactly looking for this functionality. Thanks a lot. – Silkograph Jun 10 '14 at 13:39