Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

239
Visualizações
Find span values with same class name from html string text value

How to get data-mention-value of span classes with "dx-mention" in javascript or jquery? sorry... it should be grabbed from html text string not from html page..

<p>
  <span class="dx-mention" spellcheck="false" data-marker="@" data-mention-value="AgnesGan" data-id="AgnesGan">
    <span contenteditable="false">
      <span>@</span>
      AgnesGan
    </span>
  </span> 
  <span class="dx-mention" spellcheck="false" data-marker="@" data-mention-value="AK" data-id="AK">
    <span contenteditable="false">
      <span>@</span>AK
    </span>
  </span>
</p>

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

Access the dataset property for each span with the dx-mention class. Use querySelectorAll to pick up the span elements, and then iterate over them.

dataset will return an object. However, because of the way hyphenated attributes are treated you need to target mentionValue rather than mention-value.

const spans = document.querySelectorAll('.dx-mention');

spans.forEach(span => {
  console.log(span.dataset);
  console.log(span.dataset.mentionValue);
});
<p>
  <span class="dx-mention" spellcheck="false" data-marker="@" data-mention-value="AgnesGan" data-id="AgnesGan">
<span contenteditable="false">
<span>@</span>AgnesGan</span>
  </span>
  <span class="dx-mention" spellcheck="false" data-marker="@" data-mention-value="AK" data-id="AK">
<span contenteditable="false">
<span>@</span>AK</span>
  </span>
</p>

about 4 years ago · Juan Pablo Isaza Relatório

0

You could do it like this:

$('.dx-mention').map(function() {
  return $(this).attr("data-mention-value")
}).get()

This will return both spans that is selected by the class, and get their data value.

Demo

var string = `<p><span class="dx-mention" spellcheck="false" data-marker="@" data-mention-value="AgnesGan" data-id="AgnesGan"><span contenteditable="false"><span>@</span>AgnesGan</span>
  </span> <span class="dx-mention" spellcheck="false" data-marker="@" data-mention-value="AK" data-id="AK"><span contenteditable="false"><span>@</span>AK</span>
  </span>
</p>`

var log = $('.dx-mention', string).map(function() {
  return $(this).attr("data-mention-value")
}).get()
console.log(log)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

about 4 years ago · Juan Pablo Isaza Relatório

0

You can use the following statement

document.querySelector('span.dx-mention').getAttribute('data-mention-value')

if you have multiple "span" elements you can use querySelectorAll and loop the nodes returned by the method.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda