Saturday, June 3, 2017

jQuery Script: Remove next element by class name

Its very easy to remove next element by checking class is matches or not. You can also remove previous element as well as next element.

$(".base").prev(".search").remove();

<script src="3.2.1/jquery.min.js"></script>

<div class="base">ELEMENT 1</div>
<div class="will_not_remove">ELEMENT WILL NOT REMOVE</div>
<div class="remove">HAS CLASS "REMOVE" BUT WILL NOT REMOVE</div>
<div class="base">ELEMENT 2</div>
<div class="remove">ELEMENT WILL REMOVE</div>

<script type="text/javascript">
    $(".base").next(".remove").remove();
</script>



No comments:

Post a Comment