I was just trying to do the following in jQuery:
var newCanvas = $('<canvas/>',{'width':100,'height':200,'class':'radHuh'});
$(body).append(newCanvas);
This is working (kind of) and generates the following markup:
<canvas style="width:100px; height:200px;" class="radHuh"></canvas>
As most of you might know canvas
elements don't really like CSS dimensions but expect a width and height attribute, so this object creation failed for me.
I do know I could just do:
var newCanvas = $('<canvas/>',{'class':'radHuh'}).attr({'width':100,'height':200});
instead, but I was just wondering nonetheless if there is any way of telling jQuery that width
and height
should be treated as attributes when creating the element via $('element',{attributes})
and not as CSS?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…