Agustin
Agustin

Reputation: 103

Selecting ONLY the Text of a Link with jQuery

I am trying to do something which is probably very simple but have yet to manage to figure out. In the following code I am trying to select the text within the link that reads "View Listing" WITHOUT altering the link itself.

I am doing this for translation purpose to change "View Listing" to "Ver Listado"

<div class="listing post-537">
 <div class="listing-wrap">
  <a class="button btn-primary more-link" href="http://www.inmobiliariamx.com/listado/oportinidad-terreno-en-venta/">View Listing</a>
 </div>
</div>

So far I've success tranlasting parts of this with:

jQuery(document).ready(function($){
 $( "li span:contains('Beds')" ).text("Recamaras: ");
});

But I do not know how to do it when there is an 'a' tag in the middle. What to do?

This is wordpress and I have my reasons for doing it with jQuery and NOT in the php files. Thanks.

Upvotes: 0

Views: 53

Answers (2)

Radames E. Hernandez
Radames E. Hernandez

Reputation: 4425

You can use this code to change the text of your link:

$(function() {
    $('.listing-wrap a:contains("View Listing")').text('Ver listado');
});

I hope this will be helpful.

Regards!

Upvotes: 1

Halnex
Halnex

Reputation: 4526

This will work.

$(document).ready(function($){
 $( "a.more-link:contains('View Listing')" ).text("Recamaras: ");
});

https://jsfiddle.net/t4tzxjwe/1/

Upvotes: 2

Related Questions