Dynamically create a tag tag with the for attribute

In HTML, you can assign the attribute “for” to a tag tag so that when the user clicks the tag, he selects the appropriate radio button:

<input type="radio" name="group" value="1" id="radioButtonId" />
<label for="radioButtonId">label text</label>

Problems creating a tag tag dynamically using javascript (in particular, using the JS framework prototype). For is a reserved keyword for loops. The prototype of the JS documentation shows that className is the codeword for the reserved keyword class, but it does not say what the for for codeword is. What is it?

new Element(
 'label', {
  for: 'radioButtonId'
 }
).update('label text');
+3
source share
3 answers

className DOM, class; .

, DOM, for, htmlFor.

+9

, , :

new Element(
 'label', {
  'for': 'radioButtonId'
 }
).update('label text');
+5

Have you tried quoting?

new Element('label',{'for':'radioButtonId'}).update('label text');
+1
source

Source: https://habr.com/ru/post/1782663/


All Articles