tags:

views:

18

answers:

2

Hi all,

I am doing some self-learning about JQuery and stuck over a question:
I am trying to use the JQuery next() API to grab the data from the Text Box field of Hidden type, but I failed to do so.
Here is my code:

 $(document).ready(function(){
    $(".Testing").click(function(){
    var what =  $(this).next().val();
    alert(what);
    });
 });

<span class="Testing">Hello</span><br/>
<input type="hidden" value="World">

 <span class="Testing">Hi</span><br/>
 <input type="hidden" value="There">

Could you help me solve the question please?

Reference link: http://stackoverflow.com/questions/3223446/grab-the-id-of-a-span-tag-and-add-some-value-to-a-text-box-field-according-to-whi

A: 

.next() is for jquery Objects that contain a set of dom objects.

you'd use it for things like lists. check out the documentation: http://api.jquery.com/next/

actually you should be able to do what your trying. ignore this.

Patricia
+2  A: 

You probably forgot to close the call to $(document).ready. It needs extra });

<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"  type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
    $(".Testing").click(function(){
        var what =  $(this).next().val();
        alert(what);
    });
});
</script>
</head>
<body>

<span class="Testing">Hello</span>
<input type="hidden" value="World">

<span class="Testing">Hi</span>
<input type="hidden" value="There">

</body>
</html>
nxt