मेरे पास एक div टैग है
<div id="theDiv">Where is the image?</div>
मैं div के अंदर एक छवि टैग जोड़ना चाहूंगा
अंतिम परिणाम:
<div id="theDiv"><img id="theImg" src="theImg.png" />Where is the image?</div>
मेरे पास एक div टैग है
<div id="theDiv">Where is the image?</div>
मैं div के अंदर एक छवि टैग जोड़ना चाहूंगा
अंतिम परिणाम:
<div id="theDiv"><img id="theImg" src="theImg.png" />Where is the image?</div>
जवाबों:
क्या आपने निम्नलिखित कोशिश की है:
$('#theDiv').prepend('<img id="theImg" src="theImg.png" />')
मेरे 2 सेंट:
$('#theDiv').prepend($('<img>',{id:'theImg',src:'theImg.png'}))
$("#theDiv").append("<img id='theImg' src='theImg.png'/>");
<div>जब भी image()हम फ़ंक्शन को टैग करना चाहते हैं, तो हमें इस तरह से बदलाव करना होगा:
जावास्क्रिप्ट
function image() {
var img = document.createElement("IMG");
img.src = "/images/img1.gif";
$('#image').html(img);
}
एचटीएमएल
<div id="image"></div>
<div><a href="javascript:image();">First Image</a></div>
मंजीत कुमार के पद के अलावा (उनके पास घोषणा नहीं थी)
var image = document.createElement("IMG");
image.alt = "Alt information for image";
image.setAttribute('class', 'photo');
image.src="/images/abc.jpg";
$(#TheDiv).html(image);