skip to Main Content

I need to remove http:// which is in an existing code.

I tried the following jQuery, but both codes don’t remove http://.
Would you please let me know how to remove it?

jQuery I tried:

jQuery(".elementor-button-wrapper").find("http://").each(function(){
    var linkText = $(this).text();
    $(this).remove();
});

jQuery('.elementor-button-wrapper a [href="http://]').each(function() { this.setAttribute('href', ''); }); 

Existing code:

<div class="elementor-button-wrapper">
<a href="http://https://www.myweb.com/hereis" class="elementor-button-link elementor-button elementor-size-sm" role="button">
    <span class="elementor-button-text">Read More</span>
</a>
</div>

Thank you.

2

Answers


  1. The following script should get the current value of the href attribute of the link element inside the elementor-button-wrapper div, remove the http:// string or replace it with blank, then apply the newlink back to the link’s href attribute.

    jQuery(".elementor-button-wrapper").each(function(){
            var link = jQuery(this).find("a");
            var newlink = link.attr("href").replace('http://', '');
            link.attr("href", newlink);
        });
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <div class="elementor-button-wrapper">
    <a href="http://https://www.myweb.com/hereis" class="elementor-button-link elementor-button elementor-size-sm" role="button">
        <span class="elementor-button-text">Read More</span>
    </a>
    </div>
    Login or Signup to reply.
  2. You could try this.

    function FormatLink(link, keyword) {
      var index = link.indexOf(keyword);
      if (index === -1) {
        return link;
      }
      return link.slice(0, index) + link.slice(index + keyword.length);
    }
    
    $("a").each(function() {
      if ($(this).attr("href").indexOf("http://") != -1) {
        var link = FormatLink($(this).attr("href"), 'http://');
        $(this).attr("href", link);
        console.log(link);
      }
    });
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    
    <div class="elementor-button-wrapper">
    
      <a href="http://https://www.myweb.com/hereis" class="elementor-button-link elementor-button elementor-size-sm" role="button">
        <span class="elementor-button-text">Read More</span>
      </a>
      
      <a href="http://https://www.myweb.com/hereis" class="elementor-button-link elementor-button elementor-size-sm" role="button">
        <span class="elementor-button-text">Read More</span>
      </a>
      
      <a href="https://www.myweb.com/hereis" class="elementor-button-link elementor-button elementor-size-sm" role="button">
        <span class="elementor-button-text">Read More</span>
      </a>
      
    </div>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search