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.

2
  • 1
    what are .Span1 elements, are they inputs? as if they are <span> it won't have a value, perhaps you want text()? Adding your HTML would be helpful Commented May 4, 2014 at 22:32
  • No its not input, its a span, that contains text, thank you very much, text worked. Commented May 4, 2014 at 22:35

1 Answer 1

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());
    });
});
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you very much -this- and -text- fixed the problem.
@Mike Glad it helped. :) keep rocking!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.