开发者

USe JQUery Next() API to grab the data from a hidden Text Box

I am doing some self-learning about JQuery and stuck over a question:

I am trying to use the JQuery 开发者_Python百科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: Grab the ID of a SPAN tag and add some value to a Text Box Field according to which tag has been clicked


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>


.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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜