-2

There is 4 button

<button type="button" class="addf" idu="1">Plus</button>
<button type="button" class="unf" idu="1">Min</button>

<button type="button" class="addf" idu="2">Plus</button>
<button type="button" class="unf" idu="2">Min</button>

How to delete element in the same attr with dynamic jquery? Example, if you click .addf button where attr idu="1", you will delete .unf button where attr idu="1". If you click .addf button where attr idu="2", you will delete .unf button where attr idu="2"

Tegar Santosa
  • 57
  • 1
  • 7
  • There is no `idu` attribute defined in HTML, if you want to use custom attributes then use [`data-*`](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/data-*) attributes which will at least validate under HTML 5. – David Thomas Dec 01 '18 at 19:59
  • Its just for example. In jquery, you can delete element like this **$("unf").attr("idu").remove()** but, i have more complex case above – Tegar Santosa Dec 01 '18 at 20:08
  • Tegar its very simple make some efforts and tries and you'll find it yourself .. you can start from [How to get the data-id attribute?](https://stackoverflow.com/questions/5309926/how-to-get-the-data-id-attribute) .. then you can use a selector `$('.unf[data-idu="'+ the button data-idu+'"]').remove()` – Mohamed-Yousef Dec 01 '18 at 22:35

1 Answers1

0

Anyway .. up to what @David said in his comment .. change idu= to data-idu= .. so your code should looks like this

$(document).ready(function(){
  $('.addf').on('click' , function(){
    var GetData = $(this).attr('data-idu');
    $('.unf[data-idu="'+ GetData +'"]').remove();
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button type="button" class="addf" data-idu="1">Plus</button>
<button type="button" class="unf" data-idu="1">Min</button>

<button type="button" class="addf" data-idu="2">Plus</button>
<button type="button" class="unf" data-idu="2">Min</button>
Mohamed-Yousef
  • 23,946
  • 3
  • 19
  • 28