Div etiketim var
<div id="theDiv">Where is the image?</div>
Div'ın içine resim etiketi eklemek istiyorum
Sonuç:
<div id="theDiv"><img id="theImg" src="theImg.png" />Where is the image?</div>
Div etiketim var
<div id="theDiv">Where is the image?</div>
Div'ın içine resim etiketi eklemek istiyorum
Sonuç:
<div id="theDiv"><img id="theImg" src="theImg.png" />Where is the image?</div>
Yanıtlar:
Aşağıdakileri denediniz mi:
$('#theDiv').prepend('<img id="theImg" src="theImg.png" />')
benim 2 sent:
$('#theDiv').prepend($('<img>',{id:'theImg',src:'theImg.png'}))
$("#theDiv").append("<img id='theImg' src='theImg.png'/>");
Buradaki belgeleri okumalısınız .
<div>İşlev image()çağrıldığında etiket içeriğini değiştirmek istiyorsak , bunu yapmak zorundayız:
JavaScript
function image() {
var img = document.createElement("IMG");
img.src = "/images/img1.gif";
$('#image').html(img);
}
HTML
<div id="image"></div>
<div><a href="javascript:image();">First Image</a></div>
Manjeet Kumar'ın görevine ek olarak (beyanı yoktu)
var image = document.createElement("IMG");
image.alt = "Alt information for image";
image.setAttribute('class', 'photo');
image.src="/images/abc.jpg";
$(#TheDiv).html(image);