开发者

Jquery + change label value without ID

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. Unf开发者_Python百科ortunately 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..


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');


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.


Try this

$("div.form-item lable.option").html("ValueToChange");


$('#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


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');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜