Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery + change label value without ID

Tags:

jquery

label

I have this label:

<div id="edit-my-radios-0-wrapper" class="form-item">
<label class="option" for="edit-my-radios-0">
<input id="edit-my-radios-0" class="form-radio" type="radio" value="0">
£25
</label>

Which I want to change the value of using JQuery. Unfortunately I have no control over how it is created, and with an id, I'm not sure if it's even possible to target it.

Does anyone have nay idea how to target it?

Thanks in advance..

like image 308
whistlegull Avatar asked Aug 01 '11 16:08

whistlegull


3 Answers

I realize this question is about a year old, but I thought I'd answer it anyway...

To select/target a label that doesn't have an id, you can use the value in for= as follows:

$('label[for=edit-my-radios-0]').html('New Label Here');
like image 89
Joseph Avatar answered Nov 18 '22 08:11

Joseph


I'm assuming that by value you mean the HTML inside of the label. You can select the label by the class name.

$('.option').html('[Your HTML here']);

Take a look at the jQuery selectors.

like image 28
James Hill Avatar answered Nov 18 '22 08:11

James Hill


Try this

$("div.form-item lable.option").html("ValueToChange");
like image 1
ShankarSangoli Avatar answered Nov 18 '22 07:11

ShankarSangoli