How to replace some text in href of anchor tag in jQuery


Ram Singh

I have few url anchors like "http%3a/test.dev.test.com/posts/test test" and I want to replace it with " http://test.dev.test.com/posts/test Test" on the window loading function, I have tried the following code but it does not update the url of the anchor tag.

 $('a[href*="http%3a//"]').each(function () {
      this.href = this.attr('href').replace('http%3a//', 'http://');
    });

I don't understand why it doesn't work. please help me.

edit::

<a href="http%3a//test.dev.test.com/posts/test test" rel="bookmark" class="aChangeUrl" id="ctl00_lnkEntry">New test in March</a>
Denis Segure

attrNot native DOM methods, but jQuery methods.

Change

  this.href = this.attr('href').replace('http%3a//', 'http://');

arrive

  this.href = $(this).attr('href').replace('http%3a//', 'http://');

Note that you can make the whole a bit more concise:

$('a[href^="http%3a//"]').attr('href', function(_,s) {
     return s.replace('http%3a//', 'http://');
});

Related


How to replace some text in href of anchor tag in jQuery

Ram Singh I have few url anchors like "http%3a/test.dev.test.com/posts/test test" and I want to replace it with " http://test.dev.test.com/posts/test Test" on the window loading function, I have tried the following code but it does not update the url of the an

How to replace some text in href of anchor tag in jQuery

Ram Singh I have few url anchors like "http%3a/test.dev.test.com/posts/test test" and I want to replace it with " http://test.dev.test.com/posts/test Test" on the window loading function, I have tried the following code, but it doesn't update the anchor tag's

How to replace some text in href of anchor tag in jQuery

Ram Singh I have few url anchors like "http%3a/test.dev.test.com/posts/test test" and I want to replace it with " http://test.dev.test.com/posts/test Test" on the window loading function, I have tried the following code, but it doesn't update the anchor tag's

How to map/loop 2 array values to anchor tag with href and text?

jaish I am trying to map values from 2 different arrays, one containing links and the other containing tab names . I have an anchor tag consisting of href and text string . Is there a way I can map/loop over the values in the 2 arrays to provide the values. Ap

How to convert <text> (text tag) to anchor tag in jQuery?

Archie I have a <text>label that contains plain text, but I want to display a hyperlink instead of plain text. <svg width="800" height="600" class="overlay"> <g transform="translate(100,220)"> <path class="link" d="M80,120C120,120 120,106.66666666666666

How to convert <text> (text tag) to anchor tag in jQuery?

Archie I have a <text>label that contains plain text, but I want to display a hyperlink instead of plain text. <svg width="800" height="600" class="overlay"> <g transform="translate(100,220)"> <path class="link" d="M80,120C120,120 120,106.66666666666666

How to convert <text> (text tag) to anchor tag in jQuery?

Archie I have a <text>label that contains plain text, but I want to display a hyperlink instead of plain text. <svg width="800" height="600" class="overlay"> <g transform="translate(100,220)"> <path class="link" d="M80,120C120,120 120,106.66666666666666

How to find href path of anchor tag using jquery?

Vignesh Pichamani How can i get and check if href path contains image path or other link using jquery. E.g: <a href="image.png"><img src="image.png"/></a> In the above example, the anchor text contains the image src, then only the jquery function can find the

How to find href path of anchor tag using jquery?

Vignesh Pichamani How can i get and check if href path contains image path or other link using jquery. E.g: <a href="image.png"><img src="image.png"/></a> In the above example, the anchor text contains the image src, then only the jquery function can find the

How to display div based on href of anchor tag list in jQuery

Sunil Chaudhary I have multiple anchor tags and want to match their hrefattributes. Based on the matching result, the div should be displayed. I used the code below but it didn't work. <div class="form-group search-form" style="display: none;"> <input type

How to replace anchor tag text using C#?

Balgav I am trying to replace anchor tag value using regex Regex.Match(link, @"<a [^>]*>(.*?)</a>").Groups[1].Value.ToString();This gives me the anchor tag text. I tried using "Regex.replace" but I can't replace the exact text. example: var link="<a href="">Sa

How to replace anchor tag text using C#?

Balgav I am trying to replace anchor tag value using regex Regex.Match(link, @"<a [^>]*>(.*?)</a>").Groups[1].Value.ToString();This gives me the anchor tag text. I tried using "Regex.replace" but I can't replace the exact text. example: var link="<a href="">Sa

How to replace href links in text using jQuery

Alpha reticulum cells HTML example: <p><a href='link1' target='_blank'><font color='blue' size='4'>TEXT 1</font></a></p> <br /> <p><a href='link2' target='_blank'><font color='blue' size='4'>TEXT 2</font></a></p> <br /> <p><a href='link3' target='_

How to replace href links in text using jQuery

Alpha reticulum cells HTML example: <p><a href='link1' target='_blank'><font color='blue' size='4'>TEXT 1</font></a></p> <br /> <p><a href='link2' target='_blank'><font color='blue' size='4'>TEXT 2</font></a></p> <br /> <p><a href='link3' target='_

Select anchor tag with specific href using jQuery

Joe Hart Purpose After refreshing the browser, I want the user to stay in the menu/content before the refresh. question After refreshing the browser, the content of the specific menu the user was in before the refresh was displayed as active (ie, displayed on

Select anchor tag with specific href using jQuery

Joe Hart Purpose After refreshing the browser, I want the user to stay in the menu/content before the refresh. question After refreshing the browser, the content of the specific menu the user was in before the refresh was displayed as active (ie, displayed on

Select anchor tag with specific href using jQuery

Joe Hart Purpose After refreshing the browser, I want the user to stay in the menu/content before the refresh. question After refreshing the browser, the contents of the specific menu the user was in before the refresh is displayed as active (ie, displayed on

Select anchor tag with specific href using jQuery

Joe Hart Purpose After refreshing the browser, I want the user to stay in the menu/content before the refresh. question After refreshing the browser, the content of the specific menu the user was in before the refresh was displayed as active (ie, displayed on

How to change anchor tag's text on click using jquery?

Start I want to change the text of anchor tag on click event using jquery. Anchor Tag: <a id="view_email" href="#"><i class="fa fa-envelope"></i> View Email</a> query code: <script type="text/javascript"> $(document).ready(function(){ $("#view_email").cl

Some tags in anchor tag, text indent not working

Rajaseca I created the label inside the label and applied the indent text: -9999px; but it doesn't work To be ADA compliant we need to add (new window) text in the anchor tag, but I don't want that text to be displayed so I used text-indent HTML: <a href="#" t

Some tags in anchor tag, text indent not working

Rajaseca I created the label inside the label and applied the indent text: -9999px; but it doesn't work To be ADA compliant we need to add (new window) text in the anchor tag, but I don't want that text to be displayed so I used text-indent HTML: <a href="#" t

How to open alert box in anchor tag <a href>?

Anuja Lamaheva I want to open an alert box when a certain link is clicked. How to do it? username You can also use the following code: <a href="#" id="link">Link</a> Javascript: $(document).on("click","#link",function(){ alert("I am a pop up ! "); }); eithe