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

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -