Link to home
Start Free TrialLog in
Avatar of Luv2Muff
Luv2Muff

asked on

jQuery - Replace text

Hi, I need a piece of jQuery that that scans the whole document and replaces all instances of "XXXX" with the text contained in the Meta Keywords tag, for example:

<meta name="keywords" content="YYYY" />

In this example all instances of "XXXX" will be replaced by "YYYY".

Thanks, Luv2.
Avatar of Rakesh Jaimini
Rakesh Jaimini
Flag of India image

try this

var el = $('.BodyClass');
el.html(el.html().replace(/XXXX/ig, "YYYY"));

where BodyClass will be a class set on the body of the page

Avatar of Luv2Muff
Luv2Muff

ASKER

Hi,

I am using a a CMS and cannot give the body a class, is there a way round this.

Also I do not want to replace the text with "YYYY", I just used that as an an example. I need to replace XXX with the text contained withing the Keywords Meta Tag:

<meta name="keywords" content="YYYY" />
ASKER CERTIFIED SOLUTION
Avatar of irocwebs
irocwebs

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Perfect thank you!!

Also trying to change the page title:

$(this).attr("title").replace(/XXXX/ig, keywords_seo));

This does not work, can you tell me what would?

Thanks again.
Are you doing this for the search engines? To the best of my knowledge search engines will not see these. I may be wrong but I wouldn't spend too much time looking at jquery to do the job... you'd be better off looking at php.