Somebody posted me this code to me with a problem I had:
$('#txtWeight').each( function() {
var $this = $(this);
var $weightText = $("<input type='text' class='txtWeightRow' maxlength='5' onkeypress='return isNumberKey(event)'/>").attr('name',$this.attr('name'))
.attr('value',$this.val())
$weight.append($weightText).append('%');
});
What I want to know is what does .attr('name',$this.attr('name')). Am I not going to be able to call my input to whatever name I want it to. Does this link the “name” with a previous “name”?
Thanks
Supplying a second argument to the
attrfunction sets the attribute to this value.So your example is setting the name attribute of all inputs with name
txtWeightRowto the value of the name attribute of whatever$thisis.In order to see what
$thisis you’d have to supply some more context.