There was a problem. When certain conditions in the script, I create an element and add it to the div

var video = "<video autoplay controls> <source src='" + sImgUri + "'type='video/mp4'>Your browser does not support the video tag.</video>"; oArea.append(video); 

And on the page I have such an element

 <div class="prod-img" style="background-image: none;"> <video autoplay="" controls=""> <source src="http://download.wavetlan.com/SVV/Media/HTTP/H264/Talkinghead_Media/H264_test1_Talkinghead_mp4_480x360.mp4" type="video/mp4">Your browser does not support the video tag.</video> </div> 

Next, I want to delete the tag along with the contents.

I do it like this:

 $(".prod-img video").remove(); 

But nothing happens.

Can someone tell me how to delete an item?

  • $(".prod-img").remove(); You for some specific reason are not satisfied? or not? just $(".prod-img video").remove(); must remove the video tag, and the div with the class left untouched - NumminorihSF
  • I tried it - everything works jsfiddle.net/r1tmrya7/1 if you comment out js, then you can watch the video, and if you leave, nothing is present - splash58
  • if you need to remove the video tag, then everything is ok. if there is a problem (i.e., the tag remains on the page), then it is not in ghost pieces of code. - NumminorihSF
  • @NumminorihSF you and I have already convinced each other that everything is fine. it's up to the author :) - splash58
  • Yes, it seems there was some kind of glitch. Now everything works. - Thomas Spring

2 answers 2

Everything works :

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <button onclick="$('.prod-img video').remove();">Удалить</button> <div class="prod-img" style="background-image: none;"> <video controls=""> <source src="http://download.wavetlan.com/SVV/Media/HTTP/H264/Talkinghead_Media/H264_test1_Talkinghead_mp4_480x360.mp4" type="video/mp4">Your browser does not support the video tag.</video> </div> 

Perhaps you have several of them and the wrong one is deleted or an error occurs, see the console through the "Developer Tools"

    $(".prod-img video").remove(); in this case, should remove the video tag that is inside of something with the class .prod-img . To remove the entire tag with this class is enough $(".prod-img").remove(); . More specifically, you can read about selectors, for example, here (there is no anchor, so you have to manually “dodge” the “Selectors” section).