Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

342
Vistas
How can i get text content in a nested span?

this is html and javascript code I was trying to create to get the value inside last span tag:

var value2=$('#jsVal span .EmbeddedMiniatureVisualization')[0];

console.log(value2)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<div id="jsVal">
<span id="36eb3c8a1503436b8b0a79ce1758d05a" style="">
    <span id="89e56665-5959-4e67-8fb8-83ca7cef9965" viewid="89e56665-5959-4e67-8fb8-83ca7cef9965" class="EmbeddedMiniatureVisualization" sf-busy="false" style="position: relative; margin: 0px; padding: 0px; border: 0px; overflow: hidden;">
        <span style="color: rgb(79, 79, 79); text-align: right;">53338060787</span>
    </span>
</span>
</div>

From developer tools, I see that it returns this:

<span id="89e56665-5959-4e67-8fb8-83ca7cef9965" viewid="89e56665-5959-4e67-8fb8-83ca7cef9965" class="EmbeddedMiniatureVisualization" sf-busy="false" style="position: relative; margin: 0px; padding: 0px; border: 0px; overflow: hidden;">
    <span style="color: rgb(79, 79, 79); text-align: right;">53338060787</span>
</span>

So from this, How can i get the text inside span? Is there a more straightforward way?

I tried this:

var value=$('div#jsVal span span.EmbeddedMiniatureVisualization span').text().trim();

but I get null value...

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

You could ask for the last element that doesn't have a child, at any point.. so from the top

$("#jsVal :not(:has(*))").text();

or from anywhere below

$("#jsVal span.EmbeddedMiniatureVisualization :not(:has(*))").text();

Target the highest level at which you can guarantee it is what you want, by ID or Class

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can use find like code given below

//var val=$("#jsVal .EmbeddedMiniatureVisualization").find("span").text();
//var val = $("#jsVal .EmbeddedMiniatureVisualization span")[0].innerHTML // you can also use this
//var val =$($("#jsVal .EmbeddedMiniatureVisualization span")[0]).text() //you can also use this
var val=document.querySelector("#jsVal .EmbeddedMiniatureVisualization span:nth-child(1)").textContent; // for javascript
console.log(val)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<div id="jsVal">
<span id="36eb3c8a1503436b8b0a79ce1758d05a" style="">
    <span id="89e56665-5959-4e67-8fb8-83ca7cef9965" viewid="89e56665-5959-4e67-8fb8-83ca7cef9965" class="EmbeddedMiniatureVisualization" sf-busy="false" style="position: relative; margin: 0px; padding: 0px; border: 0px; overflow: hidden;">
        <span style="color: rgb(79, 79, 79); text-align: right;">53338060787</span>
    </span>
</span>
</div>

about 4 years ago · Juan Pablo Isaza Denunciar

0

Because you are not fulling going to the element that you want in text format. I suggest to go deep and apply text to each element then only it will work.

See in the image I get two different a=output for each almost same query:

enter image description here

The first output I get is list of nan values

The second Output I get is the list of elements that I want.

See my ipynb file for your reference if you want. Here is the link

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda