Reputation: 4432
I know this is very basic. I would like to use jQuery to change the label of a drop down field which was generated by Django.
Here is the HTML code:
<div class="form-fields">
<table>
<tr><th><label for="id_Ap_m">Application method 1:</label></th><td><select name="Ap_m" id="id_Ap_m">
<option value="" selected="selected">Select an application method</option>
<option value="1">Aerial</option>
<option value="2">Ground Sprayer</option>
</select></td></tr>
</table>
</div>
jQuery code:
$(document).ready(function(){
$('#id_Ap_m').html('New application');
});
My aim is to change 'Application method 1' to 'New application'. My approach is to select this label based on its id then change the text. However, my code does not work. It could because both the label and dropdown list have the same id (id_Ap_m
), which was generated by Django.
Any suggestions?
Upvotes: 0
Views: 1069
Reputation: 146360
Your label has no id, did you try this?
$("label[for='id_Ap_m']").html('New application');
Upvotes: 6