Bacter Bacter - 7 months ago 21
jQuery Question

Javascript - change html element in each loop

Dumb question, I'm sure, but I don't know the answer.

I've got a field that I populated this way

<div class="field">
<%f.label :client_id %>
<%= :client_id,
options_for_select({ |p| [p.appointment_record,]}), # your options for this select box
include_blank: 'Select Client'

So when I get

clients = $('#appointment_client_id').html()


<option value="">Select Patient First, Please</option>
<option value="1">Guy, First - Programmer</option>
<option value="2">Guy, Second - Code Monkey</option>

What I want is to change those value tags. This list is generated dynamically.

How could I change the value tags in an .each loop so that it sticks?


It is not clear at all what you want to change or from what source.

Assuming you want to change <option> values you can use val(function) to loop through collection. The arguments of the function are index and current value


$('#appointment_client_id').children(':gt(0)').val(function(i, currVal){
    return currVal ? currVal * 10 :'';