1

My page completely designed in some jquery file for all over application so I want to do below jquery action in one page only.

How to remove an 'anchor' element from 'div' element which have group of anchors with same class and not have any Ids.

in my page i just have below element only.

<div class="tools"> </div>
</div>

so when I running the page then there shows many anchor elements from which i want to remove one anchor, which class is 'dt-button btn default'.Below is the generated code.

<div class="dt-buttons">
<a class="dt-button buttons-print btn default" tabindex="0" aria-controls="sample_2" href="#"><span>Print</span></a>
<a class="dt-button buttons-copy buttons-html5 btn default" tabindex="0" aria-controls="sample_2" href="#"><span>Copy</span></a>
<a class="dt-button buttons-pdf buttons-html5 btn default" tabindex="0" aria-controls="sample_2" href="#"><span>PDF</span></a>
<a class="dt-button buttons-excel buttons-html5 btn default" tabindex="0" aria-controls="sample_2" href="#"><span>Excel</span></a>
<a class="dt-button btn default" tabindex="0" aria-controls="sample_2" href="#"><span>Reload</span></a>
</div>

when I trying below code then remaining anchors getting effect.

$(".dt-button btn default").remove();
dawood ahmed
  • 91
  • 1
  • 10
  • Your selector is wrong, you're trying to select element(s) with *all* those classes, so the selector should be: `.dt-button.btn.default`; as currently written the selector is looking for a `` element within a `` element within an element with a class of `.dt-button`. – David Thomas Sep 29 '18 at 10:27
  • This may help: [Stack Overflow: How to remove an HTML element using Javascript?](https://stackoverflow.com/questions/5933157/how-to-remove-an-html-element-using-javascript) – enxaneta Sep 29 '18 at 10:29
  • @enxaneta I saw the link, but its diff because in that getting the element which is unique, its easy..but my problem is there is not have any unique id. – dawood ahmed Sep 29 '18 at 10:35

1 Answers1

1

I think you want to remove link which have only 3 classes dt-button,btn,default

$(document).ready(function() {
  var classestoremove = ['dt-button', 'btn', 'default'];
  $('.dt-buttons a').each(function() {
    var classes = $(this).attr('class').split(' ');
    var array3 = classes.filter(function(obj) {
      return classestoremove.indexOf(obj) == -1;
    });
    if (classes.length == 3 && array3.length == 0) {
      $(this).remove();
    }
  })
});

Working fiddle:- https://jsfiddle.net/buq2j9n0/

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98