2

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.

Bengi Besçeli
  • 3,638
  • 12
  • 53
  • 87
  • 1
    what are `.Span1` elements, are they inputs? as if they are `` it won't have a value, perhaps you want `text()`? Adding your HTML would be helpful – OJay May 04 '14 at 22:32
  • No its not input, its a span, that contains text, thank you very much, text worked. – Bengi Besçeli May 04 '14 at 22:35

1 Answers1

3

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());
    });
});
Community
  • 1
  • 1
Tats_innit
  • 33,991
  • 10
  • 71
  • 77