I am wanting to find the href in the series class and then replace the [PAGEURL] with the same link. I also need this to repeat the function for every .details class on the page.
Here is the JavaScript that I am using –
$(function() {
var links = $('.details'),
matchExp = /\[PAGEURL\]/,
currentURL = $('.series').attr('href');
links.each(function() {
var currentHREF = $(this).attr('href');
if (currentHREF.match(matchExp)) {
$(this).attr('href',currentHREF.replace(matchExp,currentURL));
}
});
});
And here is the HTML
<div class="details">
<div class="series">
<a href="MyLink.php">text</a>
</div>
<fb:comments-count href=[PAGEURL]></fb:comments-count>
</div>
I don’t think that you need to use regular expressions in this instance.
jQuery provides you with enough tools to get the job done.
Here is how I would accomplish a “search and replace” function on some link placeholders:
Given the following HTML –
This jQuery would do the trick –
The final desired result should look like this –
jsFiddle demo
I made one change to the actual HTML from your question. The value of the
hrefproperty (and any property for that matter) should always be surrounded with quotes.<fb:comments-count href=“[PAGEURL]“></fb:comments-count>