Reputation: 3081
I want to use jquery to select a specific anchor tag on my page, and apply the replace() method to it (I am trying to replace ' with %27, I am having apostrophe issues when submitting my form...) and I'm not sure exactly how to do this. I started to write this:
$(".view-subscription-admin tbody td.views-field-nothing a").attr("href
and then realized that I wasn't sure how to use this with the replace function. How would I do this?
Upvotes: 2
Views: 360
Reputation: 3081
I'm not sure why the suggested answer didn't work for me, but someone else gave me a different suggestion and this one worked:
$(document).ready(function() {
$(".view-subscription-admin tbody td.views-field-nothing a").each(function(i) {
var oldHref= $(this).attr('href');
var newHref = oldHref.replace(''', '%27');
$(this).attr('href',newHref);
});
});
Upvotes: 0
Reputation: 87073
$(".view-subscription-admin tbody td.views-field-nothing a")
.attr("href", function(i, oldHref) {
return oldHref.replace(''', '%27');
});
.attr()
method support a callback function and within that argument you can do your replace code and return that href
.
Upvotes: 4