2

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 &#039 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?

2 Answers 2

4
$(".view-subscription-admin tbody td.views-field-nothing a")
              .attr("href", function(i, oldHref) {
                   return oldHref.replace('&#039', '%27');
               });

.attr() method support a callback function and within that argument you can do your replace code and return that href.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! The only problem is that its not working for me. I know that I have the selector correct because I just tried attr("href", "hello") and it worked. I tried changing the items to replace (to something simpler) and it still did nothing...
@user1015214 Please share the link to fiddle
0

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);
  });
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.