String Manipulation with jQuery and JavaScript

String Manipulation with jQuery and JavaScript
0.0 0

#1

Hello everyone!
I will like to get the text content of a html tag in this case it is an Url and remove http:// , www, https://, http://www, https://www. here is the code that I wrote and does not work.

<div id="container">
            <span class="meta-item project-url">
                <span class="meta-label">URL</span>
                <a target="_blank" href="http://exemplo.com">http://exemplo.com</a>
            </span>
</div>

//JS

$(document).ready(function(){
        $('.project-url a').text().replace('http://', '');
        
        console.log($('.project-url a').text().replace('http://', ''));

    });
    

The Results I can see just in the console but not in me DOM , which I want to do. This is a Web Applikation that’s why I can just manipulate it with JS .


#2

Hi @pantera-bo

You need to pass the result of calling replace into the text function, at the moment you’re calling replace but not doing anything with the result.

Something like this:

$(document).ready(function() {
    var $url = $('.project-url a');
    $url.text($url.text().replace('http://', ''));

    console.log($('.project-url a').text().replace('http://', ''));
});

#3

I think this stack overflow post will help:

:slight_smile:


#4

many thanks to you 2 :smiley: