Reputation: 61
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..
Upvotes: 6
Views: 11589
Reputation: 508
it's simple please try this code
$('label[for="edit-my-radios-0"]').html('<input id="edit-my-radios-0" class="form-radio" type="radio" value="0">£180');
Upvotes: 0
Reputation: 2712
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');
Upvotes: 11
Reputation:
$('#edit-my-radios-0-wrapper label')
will get this as the wrapper has an id
. Targetting it by class
anywhere may cause trouble with other elements on the page with the same class.
-- edit --
Just seen that the div
doesn't close after the label. Looks like you can't target a specific label but can target all with $('.option')
-- edit --
I'm determined to make this a decent answer rather than what I've served up so far!
Using $('label:has(#edit-my-radios-0)')
will target that label
Upvotes: 0
Reputation: 69905
Try this
$("div.form-item lable.option").html("ValueToChange");
Upvotes: 1
Reputation: 61792
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.
Upvotes: 1