Quote:
Originally Posted by rnd me
fix your quotes below, but splitting it up into creation/appending phases gives you the extra handle you need to call .css() on an object.
Code:
var temp=$("<div id='char_'+d[0]><img src=\" + st + \"></div>");
$('#container').append(temp);
temp.css({'position' : 'absolute', 'left' : '425', 'top' : '860'});
|
Apart from the fact that this saves a DOM query, this is not really an issue, and the other approach should work just fine.
There are a bunch of other issues, though:
Code:
$('#container').append(\"<div id='char_'+d[0]><img src=\" + st + \"></div>\");
rnd me already addressed that in his snippet, but it's worth pointing out: You can't escape your quotes like that. Why would you even do that?
Code:
$('#container').append(\"<div id='char_'+d[0]><img src=\" + st + \"></div>\");
There is no variable substitution in Javascript, so those are the literal strings
"+d[0]" and
" + st + ", which is not what you want.
A working version of the code could look like that:
PHP Code:
$('#container').append('<div id="char_' + d[0] + '"><img src="' + st + '"></div>');
$('#char_' + d[0]).css({'position' : 'absolute', 'left' : 425, 'top' : 860});
But I'd definitely prefer real DOM manipulation over innerHTML:
PHP Code:
$('<div/>', {
id: 'char_' + d[0],
css: {
position: 'absolute',
left: 425,
top: 860
}
}).append(
$('<img/>', {
src: st,
alt: 'whatever'
})
).appendTo('#container');