I have seen this example on the web:
$('#questionTextArea').each( function() {
var $this = $(this);
var $questionText = $("<textarea class='textAreaQuestion'></textarea>")
.attr('name',$this.attr('name'))
.attr('value',$this.val());
$question.append($questionText);
});
Where it says ‘.attr(‘name’,$this.attr(‘name’))’, what does that mean? Does that give the same ‘name’ attribute as the ‘id’ attribute #questionTextArea or the same ‘name’ as the ‘class’ attribute ‘textAreaQuestion’?
Thanks
This is assigning the
nameattribute on each newly created<textarea>to thenameattribute of#questionTextArea.Note that since it’s an id queried, there should only be one of these, and therefore the
.each()loop is kind of unnecessary.The same thing could be accomplished with something like: