How to get input value attribute with jquery -


i'm trying target value of value attribute in input field precedes label class="selected"

<div id="placeholder"> <div id="product-options" class="options">      <input checked="checked" id="option_33295465" name="cart[add][id]" type="radio" value="33295465" class="input_hidden"/>     <label for="option_33295465" class="selected">         <span>option1</span>     </label>      <input id="option_33544344" name="cart[add][id]" type="radio" value="33544344" class="input_hidden"/>     <label for="option_33544344">         <span>option2</span>     </label>  </div> </div> 

at moment i'm trying log value, undefined each time.

$('body').on('click','#button1',function(e){     e.preventdefault();     $item = jq('#placeholder').find('.selected').prev().attr('value');     console.log($item); // logs "undefined" }); 

fiddle

jquery has seperate method retrieving value of form input: val()

$item = jq('#placeholder').find('.selected').prev().val(); 

should trick, see here


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -