I usually would create the a tag like so:
$('<a>', {href: '...'});
Adds as many attributes to the element at the start. (yes attributes
, not properties)
So you can do the same thing for items like inputs:
$('<input>',{
name: 'some_name',
id: 'some_id',
value: item_value,
readonly: 'true',
style: 'background: #eee;',
size: 15
});
Or actual divs:
$('<div>',{
id: 'some_id',
text: 'this will be inside the div'
});
Here is a fiddle example: http://jsfiddle.net/maniator/mbjgd/
EDIT
From my comment below:
The reason for this is because when you create the item, you are creating it by setting it's attributes, later on those attributes become meaningless when they are changed by something like javascript, so at that point you have to use the object's properties to get the real solution that you might be looking for.