0
私は、クラス "half_weight"を持つ親DIVでinput type = textの値を見つけようとします。しかし、私は結果NaNにを取得し、それは0.8PARENTとFINDを使用する正しい方法は何ですか?
これはHTMLで次のようになります。
<div class="add_controller amt no_space half_weight">
<div class="col s2 adds">
<a id="" href="#" class="button-minus product_quantity_down">
<i class="material-icons">remove</i>
</a>
</div>
<div class="col s2 adds">
<a href="#" class="button-plus product_quantity_up">
<i class="material-icons">add</i>
</a>
</div>
<div class="col s5 qty">
<div class="row">
<span class="col s6 qty_value">
<input type="text" name="" id="" stepquan="0.8" rtype="2" value="0.8" class="text" />
</span>
</div>
</div>
これは私のjQueryのです:
$('.button-plus').on('click', function() {
valTemp = parseFloat($(this).parent('.half_weight').find('.qty_value').siblings('input[type=text]').val());
alert(valTemp);
});
入力は 'span.qty_value'の*兄弟*が、子ではありません。セレクタの '.find( '.qty_value> input [type = text]')val()'を使用してください。 – Bergi
親を親にも変更してください。 –
また、 "parents()"を使用して、祖先をDOMツリーのいくつかのレベルまで見つけることができます。 "parent()"は1つのレベルだけをトラバースします。 – agrm