Add the img if exit then remove the image and again add the imag
I am new in Jquery and try to add the img if exit then remove the image and again add the image. Help me how to do it
My html :
<section class="text-center">
<span id="ohdaran-img-replace"><img src="assets/img/ohdadaran/nazim-ala.jpg" id="ohdaran-img-replace" width="1000" height="682" class="animated fadeInLeft animation-delay-5" "=""> <hr class="color dotted"><img src="assets/img/ohdadaran/sadoor-naib.jpg" id="ohdaran-img-replace" width="1000" height="848" class="animated fadeInLeft animation-delay-5" "=""><hr class="color dotted"><img src="assets/img/ohdadaran/sadoor.jpg" id="ohdaran-img-replace" width="1000" height="551" class="animated fadeInLeft animation-delay-5" "=""><hr class="color dotted"></span>
</section>
My JS
$("#sadoor").click(function () {
var text = $(".text-center").html();
var img = '<img src="assets/img/ohdadaran/sadoor.jpg" id="ohdaran-img-replace" width="1000" height="551" class="animated fadeInLeft animation-delay-5""><hr class="color dotted">';
if(text.search('sadoor.jpg') <= 0) {
$("#ohdaran-img-replace").prepend(img);
$(".button-caution").text($("#sadoor").text());
}
else
{
text.img.empty();
$("#ohdaran-img-replace").dettach(img);
//$(img).dettach();
$(".button-caution").text($("#sadoor").text());
}
});