Reputation: 69
I have a DIV called MainDiv. I like to replace the content of the DIV with an image on click of a button. I tried in order to replace it within the click even in Jquery but something happened.
$('#MainDiv').attr('src', 'images/Img1.jpg ');
Am I missing anything?
Upvotes: 1
Views: 6819
Reputation: 4974
<div> <img src="" id="img"/> </div>
<input type="button" id="btn" value="Click">
$(document).ready(function () {
$( "#btn" ).click(function() {
$("#img").attr("src", src);
});
});
Upvotes: 0
Reputation: 43156
You can use replaceWith()
$('#MainDiv').replaceWith("<img id='MainDiv' src='images/Img1.jpg'/>");
Upvotes: 0