开发者

Jquery get input value inside list which is inside a div

开发者 https://www.devze.com 2022-12-27 05:25 出处:网络
I have something like the following <div id=\"container开发者_开发百科\"> <ul id=\"name_list\">

I have something like the following

<div id="container开发者_开发百科">
      <ul id="name_list">
          <li class="name">
             <input type="hidden" class="name_val" value="5" />
          </li>
      </ul>
</div>

I am trying to get the value of the input. So far I have the following Jquery statment.

$("#container li.name input.name_val").val();

this does not work anyone know a better way?


You were having a typo in your input class name

$("#container li.name input.name_val").val();

Also you can change your selector to something like

$("#name_list > li.name > input:hidden.name_val").val();


Give your <input> either a name or an id. The you can get the value in either of these two ways:

$('input[name=thename]').val()

or

$('input#theid').val()


Should it be

var value = $('input.name_val').val();

You don't need to mention the other parts of the dom, just the area you are interested in.

0

精彩评论

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