Remove next element after specific tag





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I'm trying to make a "onclick" function to remove only the closer element of a specific tag!



For example:



<div>
<video src="path/video.mp4"></video>
<div>This div must be removed</div>
<div>Controls</div>
</div>


In this situation, I must search for all tags "video" in the page and remove only the next div (with "this div must be removed"). And keep the div with "controls". So I must have this as result:



<div>
<video src="path/video.mp4"></video>
<div>Controls</div>
</div>


The way I'm doing, I lost everythig:



function remove() {

var videos = document.getElementsByTagName("video");
for (var i=0;i<videos.length;i+=1){
var classe = videos[i].getAttribute("class");

parentDiv = videos[i].parentNode;
var classParent = parentDiv.getAttribute("class");
var arrayClassParent = classParent.split(' ');
var classParent = arrayClassParent[0];
var divVideo = document.getElementsByClassName(classParent)[0];

var cntnt = document.getElementsByClassName(classParent)[i];
while (cntnt.childNodes.length > 1) {
cntnt.removeChild(cntnt.lastChild);
}
}
}


Note: The div class and ID is set variable.. So I can call them using IDs and Classes...










share|improve this question

























  • Have you tried adding a class name to all the divs you want to remove then $("div.Test").remove();?

    – Abu Nooh
    Jan 4 at 0:33











  • Possible duplicate of How can i delete all divs with a certain class name?

    – Abu Nooh
    Jan 4 at 0:34











  • document.getElementsByTagName("video")[i].parentNode.children[2].remove() or sth like this :)

    – MasterOfDesaster
    Jan 4 at 0:34











  • It's not clear whether you want to remove the next div, even if it's not the next sibling, or the next sibling, even if it's not a div. Which do you want?

    – RobG
    Jan 4 at 0:44


















0















I'm trying to make a "onclick" function to remove only the closer element of a specific tag!



For example:



<div>
<video src="path/video.mp4"></video>
<div>This div must be removed</div>
<div>Controls</div>
</div>


In this situation, I must search for all tags "video" in the page and remove only the next div (with "this div must be removed"). And keep the div with "controls". So I must have this as result:



<div>
<video src="path/video.mp4"></video>
<div>Controls</div>
</div>


The way I'm doing, I lost everythig:



function remove() {

var videos = document.getElementsByTagName("video");
for (var i=0;i<videos.length;i+=1){
var classe = videos[i].getAttribute("class");

parentDiv = videos[i].parentNode;
var classParent = parentDiv.getAttribute("class");
var arrayClassParent = classParent.split(' ');
var classParent = arrayClassParent[0];
var divVideo = document.getElementsByClassName(classParent)[0];

var cntnt = document.getElementsByClassName(classParent)[i];
while (cntnt.childNodes.length > 1) {
cntnt.removeChild(cntnt.lastChild);
}
}
}


Note: The div class and ID is set variable.. So I can call them using IDs and Classes...










share|improve this question

























  • Have you tried adding a class name to all the divs you want to remove then $("div.Test").remove();?

    – Abu Nooh
    Jan 4 at 0:33











  • Possible duplicate of How can i delete all divs with a certain class name?

    – Abu Nooh
    Jan 4 at 0:34











  • document.getElementsByTagName("video")[i].parentNode.children[2].remove() or sth like this :)

    – MasterOfDesaster
    Jan 4 at 0:34











  • It's not clear whether you want to remove the next div, even if it's not the next sibling, or the next sibling, even if it's not a div. Which do you want?

    – RobG
    Jan 4 at 0:44














0












0








0








I'm trying to make a "onclick" function to remove only the closer element of a specific tag!



For example:



<div>
<video src="path/video.mp4"></video>
<div>This div must be removed</div>
<div>Controls</div>
</div>


In this situation, I must search for all tags "video" in the page and remove only the next div (with "this div must be removed"). And keep the div with "controls". So I must have this as result:



<div>
<video src="path/video.mp4"></video>
<div>Controls</div>
</div>


The way I'm doing, I lost everythig:



function remove() {

var videos = document.getElementsByTagName("video");
for (var i=0;i<videos.length;i+=1){
var classe = videos[i].getAttribute("class");

parentDiv = videos[i].parentNode;
var classParent = parentDiv.getAttribute("class");
var arrayClassParent = classParent.split(' ');
var classParent = arrayClassParent[0];
var divVideo = document.getElementsByClassName(classParent)[0];

var cntnt = document.getElementsByClassName(classParent)[i];
while (cntnt.childNodes.length > 1) {
cntnt.removeChild(cntnt.lastChild);
}
}
}


Note: The div class and ID is set variable.. So I can call them using IDs and Classes...










share|improve this question
















I'm trying to make a "onclick" function to remove only the closer element of a specific tag!



For example:



<div>
<video src="path/video.mp4"></video>
<div>This div must be removed</div>
<div>Controls</div>
</div>


In this situation, I must search for all tags "video" in the page and remove only the next div (with "this div must be removed"). And keep the div with "controls". So I must have this as result:



<div>
<video src="path/video.mp4"></video>
<div>Controls</div>
</div>


The way I'm doing, I lost everythig:



function remove() {

var videos = document.getElementsByTagName("video");
for (var i=0;i<videos.length;i+=1){
var classe = videos[i].getAttribute("class");

parentDiv = videos[i].parentNode;
var classParent = parentDiv.getAttribute("class");
var arrayClassParent = classParent.split(' ');
var classParent = arrayClassParent[0];
var divVideo = document.getElementsByClassName(classParent)[0];

var cntnt = document.getElementsByClassName(classParent)[i];
while (cntnt.childNodes.length > 1) {
cntnt.removeChild(cntnt.lastChild);
}
}
}


Note: The div class and ID is set variable.. So I can call them using IDs and Classes...







javascript dom






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 4 at 0:41









Dacre Denny

14.6k41233




14.6k41233










asked Jan 4 at 0:30









Andrezza Silva XavierAndrezza Silva Xavier

332




332













  • Have you tried adding a class name to all the divs you want to remove then $("div.Test").remove();?

    – Abu Nooh
    Jan 4 at 0:33











  • Possible duplicate of How can i delete all divs with a certain class name?

    – Abu Nooh
    Jan 4 at 0:34











  • document.getElementsByTagName("video")[i].parentNode.children[2].remove() or sth like this :)

    – MasterOfDesaster
    Jan 4 at 0:34











  • It's not clear whether you want to remove the next div, even if it's not the next sibling, or the next sibling, even if it's not a div. Which do you want?

    – RobG
    Jan 4 at 0:44



















  • Have you tried adding a class name to all the divs you want to remove then $("div.Test").remove();?

    – Abu Nooh
    Jan 4 at 0:33











  • Possible duplicate of How can i delete all divs with a certain class name?

    – Abu Nooh
    Jan 4 at 0:34











  • document.getElementsByTagName("video")[i].parentNode.children[2].remove() or sth like this :)

    – MasterOfDesaster
    Jan 4 at 0:34











  • It's not clear whether you want to remove the next div, even if it's not the next sibling, or the next sibling, even if it's not a div. Which do you want?

    – RobG
    Jan 4 at 0:44

















Have you tried adding a class name to all the divs you want to remove then $("div.Test").remove();?

– Abu Nooh
Jan 4 at 0:33





Have you tried adding a class name to all the divs you want to remove then $("div.Test").remove();?

– Abu Nooh
Jan 4 at 0:33













Possible duplicate of How can i delete all divs with a certain class name?

– Abu Nooh
Jan 4 at 0:34





Possible duplicate of How can i delete all divs with a certain class name?

– Abu Nooh
Jan 4 at 0:34













document.getElementsByTagName("video")[i].parentNode.children[2].remove() or sth like this :)

– MasterOfDesaster
Jan 4 at 0:34





document.getElementsByTagName("video")[i].parentNode.children[2].remove() or sth like this :)

– MasterOfDesaster
Jan 4 at 0:34













It's not clear whether you want to remove the next div, even if it's not the next sibling, or the next sibling, even if it's not a div. Which do you want?

– RobG
Jan 4 at 0:44





It's not clear whether you want to remove the next div, even if it's not the next sibling, or the next sibling, even if it's not a div. Which do you want?

– RobG
Jan 4 at 0:44












2 Answers
2






active

oldest

votes


















1














Perhaps you could use the nextElementSibling field to access and remove the element directly after each video in your document? So something along the lines of this might work for you:






function removeElementNextToVideo() {

// Query for all video elements in document
for(const video of document.body.querySelectorAll('video')) {

// For each video, check for and remove the element directly
// after (next) to it
if(video.nextElementSibling) {

video.nextElementSibling.remove();
}
}
}

removeElementNextToVideo();

<div>
<video src="path/video.mp4"></video>
<div>This div must be removed</div>
<div>Controls</div>
</div>





Also, if you want to remove the next element only if it is a DIV you can do the following:






function removeDivNextToVideo() {

// Query for all video elements in document
for(const video of document.body.querySelectorAll('video')) {

// For each video, check for and remove the element directly
// after (next) to it only if the element is a DIV
if(video.nextElementSibling && video.nextElementSibling.tagName === 'DIV') {

video.nextElementSibling.remove();
}
}
}

removeDivNextToVideo();

<div>
<video src="path/video.mp4"></video>
<h4>H4 directly after video, so nothing gets removed</h4>
<div>This div must be removed</div>
<div>Controls</div>
</div>








share|improve this answer


























  • @TinyGiant—it's not easy to spot, see Interface NodeList, where it's defined as iterable. I really don't like the current "living standard" that doesn't tell you when features were introduced or the changes made between versions (which seem to be published almost daily).

    – RobG
    Jan 4 at 0:50











  • @RobG thanks for that - I've updated the answer to inculde a solution for both cases

    – Dacre Denny
    Jan 4 at 1:11



















0














In modern browsers you can a selector with an Adjacent sibling combinator video + div to select div elements that immediately follow a video element, e.g.






function removeDivs() {
document.querySelectorAll('video + div').forEach(div => div.parentNode.removeChild(div));
}

video {height: 10px; border: 1px solid red;}

<div>
<video src="path/video.mp4"></video>
<div>This div must be removed</div>
<div>Controls</div>
</div>
<div>
<video src="path/video.mp4"></video>
<div>This div must be removed</div>
<div>Controls</div>
</div>
<button onclick="removeDivs()">Remove divs</button>








share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54031685%2fremove-next-element-after-specific-tag%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Perhaps you could use the nextElementSibling field to access and remove the element directly after each video in your document? So something along the lines of this might work for you:






    function removeElementNextToVideo() {

    // Query for all video elements in document
    for(const video of document.body.querySelectorAll('video')) {

    // For each video, check for and remove the element directly
    // after (next) to it
    if(video.nextElementSibling) {

    video.nextElementSibling.remove();
    }
    }
    }

    removeElementNextToVideo();

    <div>
    <video src="path/video.mp4"></video>
    <div>This div must be removed</div>
    <div>Controls</div>
    </div>





    Also, if you want to remove the next element only if it is a DIV you can do the following:






    function removeDivNextToVideo() {

    // Query for all video elements in document
    for(const video of document.body.querySelectorAll('video')) {

    // For each video, check for and remove the element directly
    // after (next) to it only if the element is a DIV
    if(video.nextElementSibling && video.nextElementSibling.tagName === 'DIV') {

    video.nextElementSibling.remove();
    }
    }
    }

    removeDivNextToVideo();

    <div>
    <video src="path/video.mp4"></video>
    <h4>H4 directly after video, so nothing gets removed</h4>
    <div>This div must be removed</div>
    <div>Controls</div>
    </div>








    share|improve this answer


























    • @TinyGiant—it's not easy to spot, see Interface NodeList, where it's defined as iterable. I really don't like the current "living standard" that doesn't tell you when features were introduced or the changes made between versions (which seem to be published almost daily).

      – RobG
      Jan 4 at 0:50











    • @RobG thanks for that - I've updated the answer to inculde a solution for both cases

      – Dacre Denny
      Jan 4 at 1:11
















    1














    Perhaps you could use the nextElementSibling field to access and remove the element directly after each video in your document? So something along the lines of this might work for you:






    function removeElementNextToVideo() {

    // Query for all video elements in document
    for(const video of document.body.querySelectorAll('video')) {

    // For each video, check for and remove the element directly
    // after (next) to it
    if(video.nextElementSibling) {

    video.nextElementSibling.remove();
    }
    }
    }

    removeElementNextToVideo();

    <div>
    <video src="path/video.mp4"></video>
    <div>This div must be removed</div>
    <div>Controls</div>
    </div>





    Also, if you want to remove the next element only if it is a DIV you can do the following:






    function removeDivNextToVideo() {

    // Query for all video elements in document
    for(const video of document.body.querySelectorAll('video')) {

    // For each video, check for and remove the element directly
    // after (next) to it only if the element is a DIV
    if(video.nextElementSibling && video.nextElementSibling.tagName === 'DIV') {

    video.nextElementSibling.remove();
    }
    }
    }

    removeDivNextToVideo();

    <div>
    <video src="path/video.mp4"></video>
    <h4>H4 directly after video, so nothing gets removed</h4>
    <div>This div must be removed</div>
    <div>Controls</div>
    </div>








    share|improve this answer


























    • @TinyGiant—it's not easy to spot, see Interface NodeList, where it's defined as iterable. I really don't like the current "living standard" that doesn't tell you when features were introduced or the changes made between versions (which seem to be published almost daily).

      – RobG
      Jan 4 at 0:50











    • @RobG thanks for that - I've updated the answer to inculde a solution for both cases

      – Dacre Denny
      Jan 4 at 1:11














    1












    1








    1







    Perhaps you could use the nextElementSibling field to access and remove the element directly after each video in your document? So something along the lines of this might work for you:






    function removeElementNextToVideo() {

    // Query for all video elements in document
    for(const video of document.body.querySelectorAll('video')) {

    // For each video, check for and remove the element directly
    // after (next) to it
    if(video.nextElementSibling) {

    video.nextElementSibling.remove();
    }
    }
    }

    removeElementNextToVideo();

    <div>
    <video src="path/video.mp4"></video>
    <div>This div must be removed</div>
    <div>Controls</div>
    </div>





    Also, if you want to remove the next element only if it is a DIV you can do the following:






    function removeDivNextToVideo() {

    // Query for all video elements in document
    for(const video of document.body.querySelectorAll('video')) {

    // For each video, check for and remove the element directly
    // after (next) to it only if the element is a DIV
    if(video.nextElementSibling && video.nextElementSibling.tagName === 'DIV') {

    video.nextElementSibling.remove();
    }
    }
    }

    removeDivNextToVideo();

    <div>
    <video src="path/video.mp4"></video>
    <h4>H4 directly after video, so nothing gets removed</h4>
    <div>This div must be removed</div>
    <div>Controls</div>
    </div>








    share|improve this answer















    Perhaps you could use the nextElementSibling field to access and remove the element directly after each video in your document? So something along the lines of this might work for you:






    function removeElementNextToVideo() {

    // Query for all video elements in document
    for(const video of document.body.querySelectorAll('video')) {

    // For each video, check for and remove the element directly
    // after (next) to it
    if(video.nextElementSibling) {

    video.nextElementSibling.remove();
    }
    }
    }

    removeElementNextToVideo();

    <div>
    <video src="path/video.mp4"></video>
    <div>This div must be removed</div>
    <div>Controls</div>
    </div>





    Also, if you want to remove the next element only if it is a DIV you can do the following:






    function removeDivNextToVideo() {

    // Query for all video elements in document
    for(const video of document.body.querySelectorAll('video')) {

    // For each video, check for and remove the element directly
    // after (next) to it only if the element is a DIV
    if(video.nextElementSibling && video.nextElementSibling.tagName === 'DIV') {

    video.nextElementSibling.remove();
    }
    }
    }

    removeDivNextToVideo();

    <div>
    <video src="path/video.mp4"></video>
    <h4>H4 directly after video, so nothing gets removed</h4>
    <div>This div must be removed</div>
    <div>Controls</div>
    </div>








    function removeElementNextToVideo() {

    // Query for all video elements in document
    for(const video of document.body.querySelectorAll('video')) {

    // For each video, check for and remove the element directly
    // after (next) to it
    if(video.nextElementSibling) {

    video.nextElementSibling.remove();
    }
    }
    }

    removeElementNextToVideo();

    <div>
    <video src="path/video.mp4"></video>
    <div>This div must be removed</div>
    <div>Controls</div>
    </div>





    function removeElementNextToVideo() {

    // Query for all video elements in document
    for(const video of document.body.querySelectorAll('video')) {

    // For each video, check for and remove the element directly
    // after (next) to it
    if(video.nextElementSibling) {

    video.nextElementSibling.remove();
    }
    }
    }

    removeElementNextToVideo();

    <div>
    <video src="path/video.mp4"></video>
    <div>This div must be removed</div>
    <div>Controls</div>
    </div>





    function removeDivNextToVideo() {

    // Query for all video elements in document
    for(const video of document.body.querySelectorAll('video')) {

    // For each video, check for and remove the element directly
    // after (next) to it only if the element is a DIV
    if(video.nextElementSibling && video.nextElementSibling.tagName === 'DIV') {

    video.nextElementSibling.remove();
    }
    }
    }

    removeDivNextToVideo();

    <div>
    <video src="path/video.mp4"></video>
    <h4>H4 directly after video, so nothing gets removed</h4>
    <div>This div must be removed</div>
    <div>Controls</div>
    </div>





    function removeDivNextToVideo() {

    // Query for all video elements in document
    for(const video of document.body.querySelectorAll('video')) {

    // For each video, check for and remove the element directly
    // after (next) to it only if the element is a DIV
    if(video.nextElementSibling && video.nextElementSibling.tagName === 'DIV') {

    video.nextElementSibling.remove();
    }
    }
    }

    removeDivNextToVideo();

    <div>
    <video src="path/video.mp4"></video>
    <h4>H4 directly after video, so nothing gets removed</h4>
    <div>This div must be removed</div>
    <div>Controls</div>
    </div>






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jan 4 at 1:10

























    answered Jan 4 at 0:38









    Dacre DennyDacre Denny

    14.6k41233




    14.6k41233













    • @TinyGiant—it's not easy to spot, see Interface NodeList, where it's defined as iterable. I really don't like the current "living standard" that doesn't tell you when features were introduced or the changes made between versions (which seem to be published almost daily).

      – RobG
      Jan 4 at 0:50











    • @RobG thanks for that - I've updated the answer to inculde a solution for both cases

      – Dacre Denny
      Jan 4 at 1:11



















    • @TinyGiant—it's not easy to spot, see Interface NodeList, where it's defined as iterable. I really don't like the current "living standard" that doesn't tell you when features were introduced or the changes made between versions (which seem to be published almost daily).

      – RobG
      Jan 4 at 0:50











    • @RobG thanks for that - I've updated the answer to inculde a solution for both cases

      – Dacre Denny
      Jan 4 at 1:11

















    @TinyGiant—it's not easy to spot, see Interface NodeList, where it's defined as iterable. I really don't like the current "living standard" that doesn't tell you when features were introduced or the changes made between versions (which seem to be published almost daily).

    – RobG
    Jan 4 at 0:50





    @TinyGiant—it's not easy to spot, see Interface NodeList, where it's defined as iterable. I really don't like the current "living standard" that doesn't tell you when features were introduced or the changes made between versions (which seem to be published almost daily).

    – RobG
    Jan 4 at 0:50













    @RobG thanks for that - I've updated the answer to inculde a solution for both cases

    – Dacre Denny
    Jan 4 at 1:11





    @RobG thanks for that - I've updated the answer to inculde a solution for both cases

    – Dacre Denny
    Jan 4 at 1:11













    0














    In modern browsers you can a selector with an Adjacent sibling combinator video + div to select div elements that immediately follow a video element, e.g.






    function removeDivs() {
    document.querySelectorAll('video + div').forEach(div => div.parentNode.removeChild(div));
    }

    video {height: 10px; border: 1px solid red;}

    <div>
    <video src="path/video.mp4"></video>
    <div>This div must be removed</div>
    <div>Controls</div>
    </div>
    <div>
    <video src="path/video.mp4"></video>
    <div>This div must be removed</div>
    <div>Controls</div>
    </div>
    <button onclick="removeDivs()">Remove divs</button>








    share|improve this answer




























      0














      In modern browsers you can a selector with an Adjacent sibling combinator video + div to select div elements that immediately follow a video element, e.g.






      function removeDivs() {
      document.querySelectorAll('video + div').forEach(div => div.parentNode.removeChild(div));
      }

      video {height: 10px; border: 1px solid red;}

      <div>
      <video src="path/video.mp4"></video>
      <div>This div must be removed</div>
      <div>Controls</div>
      </div>
      <div>
      <video src="path/video.mp4"></video>
      <div>This div must be removed</div>
      <div>Controls</div>
      </div>
      <button onclick="removeDivs()">Remove divs</button>








      share|improve this answer


























        0












        0








        0







        In modern browsers you can a selector with an Adjacent sibling combinator video + div to select div elements that immediately follow a video element, e.g.






        function removeDivs() {
        document.querySelectorAll('video + div').forEach(div => div.parentNode.removeChild(div));
        }

        video {height: 10px; border: 1px solid red;}

        <div>
        <video src="path/video.mp4"></video>
        <div>This div must be removed</div>
        <div>Controls</div>
        </div>
        <div>
        <video src="path/video.mp4"></video>
        <div>This div must be removed</div>
        <div>Controls</div>
        </div>
        <button onclick="removeDivs()">Remove divs</button>








        share|improve this answer













        In modern browsers you can a selector with an Adjacent sibling combinator video + div to select div elements that immediately follow a video element, e.g.






        function removeDivs() {
        document.querySelectorAll('video + div').forEach(div => div.parentNode.removeChild(div));
        }

        video {height: 10px; border: 1px solid red;}

        <div>
        <video src="path/video.mp4"></video>
        <div>This div must be removed</div>
        <div>Controls</div>
        </div>
        <div>
        <video src="path/video.mp4"></video>
        <div>This div must be removed</div>
        <div>Controls</div>
        </div>
        <button onclick="removeDivs()">Remove divs</button>








        function removeDivs() {
        document.querySelectorAll('video + div').forEach(div => div.parentNode.removeChild(div));
        }

        video {height: 10px; border: 1px solid red;}

        <div>
        <video src="path/video.mp4"></video>
        <div>This div must be removed</div>
        <div>Controls</div>
        </div>
        <div>
        <video src="path/video.mp4"></video>
        <div>This div must be removed</div>
        <div>Controls</div>
        </div>
        <button onclick="removeDivs()">Remove divs</button>





        function removeDivs() {
        document.querySelectorAll('video + div').forEach(div => div.parentNode.removeChild(div));
        }

        video {height: 10px; border: 1px solid red;}

        <div>
        <video src="path/video.mp4"></video>
        <div>This div must be removed</div>
        <div>Controls</div>
        </div>
        <div>
        <video src="path/video.mp4"></video>
        <div>This div must be removed</div>
        <div>Controls</div>
        </div>
        <button onclick="removeDivs()">Remove divs</button>






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 4 at 0:59









        RobGRobG

        99.7k19111146




        99.7k19111146






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54031685%2fremove-next-element-after-specific-tag%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Monofisismo

            Angular Downloading a file using contenturl with Basic Authentication

            Olmecas