cut text in a string in jquery

0

I am using the google api and it brings me an ajax with the variable " adr_address " and inside the following datum:

"<span class="street-address">Calle 54</span>, 
<span class="extended-address">Mercedes Barrera</span>, 
<span class="locality">Mérida</span>,
<span class="region">Yuc.</span>, <span class="country-name">México</span>"

How to search only inside the string:

<span class="extended-address">Mercedes Barrera</span>

And get the final result " Mercedes Barrera ".

    
asked by Luis Alberto Cárdenas Vargas 16.09.2017 в 00:25
source

2 answers

0

You can do it using the Jquery% filter() function:

$contenido = $('<span class="extended-address">Mercedes Barrera</span>')
console.log($contenido.filter('.extended-address').text());

this will show by console:

Mercedes Barrera
    
answered by 16.09.2017 / 00:40
source
0

Taking the ELM response as a reference. By containing a string with $ () it can be handled as if it were an HTML element and hence apply the filter function.

var jsonResult = '<span class="street-address">Calle 54</span>, <span class="extended-address">Mercedes Barrera</span>, <span class="locality">Mérida</span>, <span class="region">Yuc.</span>, <span class="country-name">México</span>';
console.log($(jsonResult).filter('.extended-address').text());
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    
answered by 16.09.2017 в 01:10