Do this:

$('label').each(function(i){
  $(this).attr('for', i).prev().attr('id', i);
});

----
Read jQuery HowTo Resource  -  http://jquery-howto.blogspot.com



On Thu, Feb 5, 2009 at 7:25 PM, paulinstl <paulsha...@gmail.com> wrote:
>
> I have a series of labels and checkboxes.
>
> The checkboxes' IDs are generated on the fly, so I have no way of
> knowing the id at the server (without a lot of heavy lifting).
>
> I'd like to do this in jquery...
>
> here's what I have so far
>
> HTML
> <input id="Checkbox1" type="checkbox" value="x" /><label>something</
> label><br />
> <input id="Checkbox2" type="checkbox" value="x" /><label>something</
> label><br />
> <input id="Checkbox3" type="checkbox" value="x" /><label>something</
> label><br />
> <input id="Checkbox4" type="checkbox" value="x" /><label>something</
> label><br />
>
> jquery
>
> $("label").attr("for", $
> (this).somethingToGoHereToSetTheIdOfThePrevElement.text
> ()                      );
>
> I'm missing the way to traverse this

Reply via email to