Skip to content

Instantly share code, notes, and snippets.

@crova
Created July 9, 2018 14:03
Show Gist options
  • Save crova/dd56e2772d595a2d978f01bf7ca91baa to your computer and use it in GitHub Desktop.
Save crova/dd56e2772d595a2d978f01bf7ca91baa to your computer and use it in GitHub Desktop.
trying to replace href
<script>
$(function () {
var terms = {
"email": { //set your term name
"default": "" //set your default value
}, //don't forget commas to separate terms
"aff_sub": {
"default": "not given"
}
};
$.each(terms,function (name, settings) {
var value = getURLParameter(name);
var regex = new RegExp("\\{\\{"+name+"\\}\\}","g");
if (!value || value == "null") {
value = settings.default;
}
$(".elButton:contains('{{"+name+"}}'), .elTextblock:contains('{{"+name+"}}'), .elHeadline:contains('{{"+name+"}}'), .elBullet:contains('{{"+name+"}}')").each(function() {
var replaced = $(this).href().replace(regex, value);
$(this).href(replaced);
});
});
});
</script>
<script>
$(function () {
var terms = {
"email": { //set your term name
"default": "" //set your default value
}, //don't forget commas to separate terms
"aff_sub": {
"default": "not given"
}
};
$.each(terms,function (name, settings) {
var value = getURLParameter(name);
var regex = new RegExp("\\{\\{"+name+"\\}\\}","g");
if (!value || value == "null") {
value = settings.default;
}
$(".elButton:contains('{{"+name+"}}'), .elTextblock:contains('{{"+name+"}}'), .elHeadline:contains('{{"+name+"}}'), .elBullet:contains('{{"+name+"}}')").each(function() {
var replaced = $(this).html().replace(regex, value);
$(this).html(replaced);
});
$(".elButton:contains('{{"+name+"}}')").each(function() { // this does not work as I thought
var replaced = $(this).href().replace(regex, value);
$(this).href(replaced);
});
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment