Pregunta

How can I get this value ? This not works :

<script type="text/javascript" src="/theme/js/jquery1.8.0/jquery.min.js"></script>
<script type="text/javascript">
    $('.Text1').click(function () {
        $('.Span1').each(function () {
            alert($('.Span1').val());
        });
    });
</script>

I need to get the Span1's value. What I'm doing wrong ?

Edit : Span1 elements are <span>, that contains text.

¿Fue útil?

Solución

demo http://jsfiddle.net/6NTeK/

You are missing : this & use text to grab text.

Hope rest fits your need :)

Code

$('.Text1').click(function () {
    $('.Span1').each(function () {
        alert($(this).text());
    });
});
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top