[jQuery] Re: dynamically building the for attribute

2009-02-09 Thread paulinstl

Thanks Mauricio,

I know that :checkbox will work, jQuery documentation states that
using input:checkbox is more readable and actually performs better.
But yes, your code worked well!

On Feb 5, 11:02 am, Mauricio \(Maujor\) Samy Silva
css.mau...@gmail.com wrote:
 Hi Paul,

 $(':checkbox') matches all inputs elements whose type is checkbox.
 Inputs are implied in this selector, so you don't need modify it. :)

 Maurício

 -Mensagem Original-
 De: paulinstl paulsha...@gmail.com
 Para: jQuery (English) jquery-en@googlegroups.com
 Enviada em: quinta-feira, 5 de fevereiro de 2009 14:28
 Assunto: [jQuery] Re: dynamically building the for attribute

 Mauricio,

 This was exactly what I needed... I modified it a bit (:checkbox to
 input:checkbox) and closed out the function.

 $('#searchresults  div  label').each(function() { var checkboxId = $
 (this).prev('input:checkbox').attr('id'); $(this).attr('for',
 checkboxId) });

 On Feb 5, 8:52 am, Mauricio \(Maujor\) Samy Silva



 css.mau...@gmail.com wrote:
  $('#my-form label').each(function() {
  var checkboxId = $(this).prev(':checkbox').attr('id')
  $(this).attr('for', checkboxId)

  Maurício

  -Mensagem Original-
  De: paulinstl paulsha...@gmail.com
  Para: jQuery (English) jquery-en@googlegroups.com
  Enviada em: quinta-feira, 5 de fevereiro de 2009 12:25
  Assunto: [jQuery] dynamically building the for attribute

   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 /labelsomething/
   labelbr /
   input id=Checkbox2 type=checkbox value=x /labelsomething/
   labelbr /
   input id=Checkbox3 type=checkbox value=x /labelsomething/
   labelbr /
   input id=Checkbox4 type=checkbox value=x /labelsomething/
   labelbr /

   jquery

   $(label).attr(for, $
   (this).somethingToGoHereToSetTheIdOfThePrevElement.text
   () );

   I'm missing the way to traverse this- Hide quoted text -

  - Show quoted text -- Hide quoted text -

 - Show quoted text -


[jQuery] Re: dynamically building the for attribute

2009-02-06 Thread jQuery Lover

Ups, I missed the id's of checkboxes... My code was written for
checkboxes and label's both without id's...


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



On Thu, Feb 5, 2009 at 7:52 PM, Mauricio (Maujor) Samy Silva
css.mau...@gmail.com wrote:

 $('#my-form label').each(function() {
  var checkboxId = $(this).prev(':checkbox').attr('id')
  $(this).attr('for', checkboxId)


 Maurício

 -Mensagem Original- De: paulinstl paulsha...@gmail.com
 Para: jQuery (English) jquery-en@googlegroups.com
 Enviada em: quinta-feira, 5 de fevereiro de 2009 12:25
 Assunto: [jQuery] dynamically building the for attribute



 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 /labelsomething/
 labelbr /
 input id=Checkbox2 type=checkbox value=x /labelsomething/
 labelbr /
 input id=Checkbox3 type=checkbox value=x /labelsomething/
 labelbr /
 input id=Checkbox4 type=checkbox value=x /labelsomething/
 labelbr /

 jquery

 $(label).attr(for, $
 (this).somethingToGoHereToSetTheIdOfThePrevElement.text
 ()  );

 I'm missing the way to traverse this




[jQuery] Re: dynamically building the for attribute

2009-02-05 Thread Liam Potter


try this

$(label).each(function (i) {
$(this).attr({ id: 'div' + ++i })
});


paulinstl 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 /labelsomething/
labelbr /
input id=Checkbox2 type=checkbox value=x /labelsomething/
labelbr /
input id=Checkbox3 type=checkbox value=x /labelsomething/
labelbr /
input id=Checkbox4 type=checkbox value=x /labelsomething/
labelbr /

jquery

$(label).attr(for, $
(this).somethingToGoHereToSetTheIdOfThePrevElement.text
()  );

I'm missing the way to traverse this
  


[jQuery] Re: dynamically building the for attribute

2009-02-05 Thread jQuery Lover

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 /labelsomething/
 labelbr /
 input id=Checkbox2 type=checkbox value=x /labelsomething/
 labelbr /
 input id=Checkbox3 type=checkbox value=x /labelsomething/
 labelbr /
 input id=Checkbox4 type=checkbox value=x /labelsomething/
 labelbr /

 jquery

 $(label).attr(for, $
 (this).somethingToGoHereToSetTheIdOfThePrevElement.text
 ()  );

 I'm missing the way to traverse this


[jQuery] Re: dynamically building the for attribute

2009-02-05 Thread Mauricio (Maujor) Samy Silva


$('#my-form label').each(function() {
  var checkboxId = $(this).prev(':checkbox').attr('id')
  $(this).attr('for', checkboxId)


Maurício

-Mensagem Original- 
De: paulinstl paulsha...@gmail.com

Para: jQuery (English) jquery-en@googlegroups.com
Enviada em: quinta-feira, 5 de fevereiro de 2009 12:25
Assunto: [jQuery] dynamically building the for attribute




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 /labelsomething/
labelbr /
input id=Checkbox2 type=checkbox value=x /labelsomething/
labelbr /
input id=Checkbox3 type=checkbox value=x /labelsomething/
labelbr /
input id=Checkbox4 type=checkbox value=x /labelsomething/
labelbr /

jquery

$(label).attr(for, $
(this).somethingToGoHereToSetTheIdOfThePrevElement.text
()  );

I'm missing the way to traverse this 




[jQuery] Re: dynamically building the for attribute

2009-02-05 Thread paulinstl

Mauricio,

This was exactly what I needed... I modified it a bit (:checkbox to
input:checkbox) and closed out the function.

$('#searchresults  div  label').each(function() { var checkboxId = $
(this).prev('input:checkbox').attr('id'); $(this).attr('for',
checkboxId) });


On Feb 5, 8:52 am, Mauricio \(Maujor\) Samy Silva
css.mau...@gmail.com wrote:
  $('#my-form label').each(function() {
        var checkboxId = $(this).prev(':checkbox').attr('id')
        $(this).attr('for', checkboxId)

 Maurício

 -Mensagem Original-
 De: paulinstl paulsha...@gmail.com
 Para: jQuery (English) jquery-en@googlegroups.com
 Enviada em: quinta-feira, 5 de fevereiro de 2009 12:25
 Assunto: [jQuery] dynamically building the for attribute





  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 /labelsomething/
  labelbr /
  input id=Checkbox2 type=checkbox value=x /labelsomething/
  labelbr /
  input id=Checkbox3 type=checkbox value=x /labelsomething/
  labelbr /
  input id=Checkbox4 type=checkbox value=x /labelsomething/
  labelbr /

  jquery

  $(label).attr(for, $
  (this).somethingToGoHereToSetTheIdOfThePrevElement.text
  ()                      );

  I'm missing the way to traverse this- Hide quoted text -

 - Show quoted text -


[jQuery] Re: dynamically building the for attribute

2009-02-05 Thread Mauricio (Maujor) Samy Silva


Hi Paul,

$(':checkbox') matches all inputs elements whose type is checkbox.
Inputs are implied in this selector, so you don't need modify it. :)

Maurício

-Mensagem Original- 
De: paulinstl paulsha...@gmail.com

Para: jQuery (English) jquery-en@googlegroups.com
Enviada em: quinta-feira, 5 de fevereiro de 2009 14:28
Assunto: [jQuery] Re: dynamically building the for attribute



Mauricio,

This was exactly what I needed... I modified it a bit (:checkbox to
input:checkbox) and closed out the function.

$('#searchresults  div  label').each(function() { var checkboxId = $
(this).prev('input:checkbox').attr('id'); $(this).attr('for',
checkboxId) });


On Feb 5, 8:52 am, Mauricio \(Maujor\) Samy Silva
css.mau...@gmail.com wrote:

$('#my-form label').each(function() {
var checkboxId = $(this).prev(':checkbox').attr('id')
$(this).attr('for', checkboxId)

Maurício

-Mensagem Original-
De: paulinstl paulsha...@gmail.com
Para: jQuery (English) jquery-en@googlegroups.com
Enviada em: quinta-feira, 5 de fevereiro de 2009 12:25
Assunto: [jQuery] dynamically building the for attribute





 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 /labelsomething/
 labelbr /
 input id=Checkbox2 type=checkbox value=x /labelsomething/
 labelbr /
 input id=Checkbox3 type=checkbox value=x /labelsomething/
 labelbr /
 input id=Checkbox4 type=checkbox value=x /labelsomething/
 labelbr /

 jquery

 $(label).attr(for, $
 (this).somethingToGoHereToSetTheIdOfThePrevElement.text
 () );

 I'm missing the way to traverse this- Hide quoted text -

- Show quoted text -