Solution 1 :

give Id to td tag and hide with jquery

here is solution

HTML

<td id="myid" class="t-c dropdown">
  <span class="dropbtn"><i class="fa fa-ellipsis-v" aria-hidden="true"></i></span>
  <div class="drop-content">
    <a id="edit" href="modify-news?nid='.$rows["id"].'" class="icon">Edit</a>
    <a id="draft" role="button" class="icon" data-id="'.$rows["id"].'" data-action="drafted">Draft</a>
    <a id="delete" role="button" class="icon" data-id="'.$rows["id"].'" data-action="deleted">Delete</a>
  </div>
</td>

JAVASCRIPT

$(document).on("click", "[data-action]", function(e){
  e.preventDefault();

  if(window.confirm("Are you sure to draft this Article?")){
    var draft_id = $(this).attr("data-id");
    var action = $(this).attr("data-action");

    $.ajax({
      url: "actions-recipe",
      type: "post",
      data: {
          draft_id:draft_id,
          action:action
      },
      success: function(data){
          $("#myid").hide()
      }
    });
  }else{
    return false;
  }
});

Solution 2 :

You need to add below code in your success action.

success: function(data){
     $('a[data-action = '+action+']').closest('td.dropdown').hide();
}

Solution 3 :

js:

document.querySelector('td.t-c.dropdown').classList.add('hidden');

or jquery

$('td.t-c.dropdown').addClass('hidden');

css:

td.t-c.dropdown.hidden {
    display:none;
}

Problem :

I’ve made an AdminCP to manage all my recipes, users, details etc… So, I’m running this code here that move my recipes from shared to drafted. Everything is fine, it’s normally working but I would like to hide the TD that It contains the button that I’ve clicked.

     $(document).on("click", "[data-action]", function(e){
        e.preventDefault();
        
        if(window.confirm("Are you sure to draft this Article?")){
            var draft_id = $(this).attr("data-id");
            var action = $(this).attr("data-action");
           
            $.ajax({
                url: "actions-recipe",
                type: "post",
                data: {
                    draft_id:draft_id,
                    action:action
                },
                success: function(data){
                    // I would like to hide the td that it contains this button
                }
            });
        }else{
            return false;
        }
    });

Html:

                 <td class="t-c dropdown">
                    <span class="dropbtn"><i class="fa fa-ellipsis-v" aria-hidden="true"></i></span>
                    <div class="drop-content">
                    <a id="edit" href="modify-news?nid='.$rows["id"].'" class="icon">Edit</a>
                    <a id="draft" role="button" class="icon" data-id="'.$rows["id"].'" data-action="drafted">Draft</a>
                    <a id="delete" role="button" class="icon" data-id="'.$rows["id"].'" data-action="deleted">Delete</a>
                    </div>
                </td>

What can I do? Any idea? Thanks everyone! 🙂

Comments

Comment posted by Vitto Alloggio

Hi, thanks for your helping! Yep, i’ve done it but i’ve got only one question: because i’ve got only one div as td, what it happens if i’ve got multiple td? I will hide all of them or just the td that it contains the button that i’ve clicked?

Comment posted by stackoverflow.com/a/65596953/6082661

check this :

Comment posted by Jun

@VittoAlloggio I’m glad it helped. To answer the question, only the td that got “myid” will hide. another td tag will not hide if you don’t give the same id

Comment posted by Vitto Alloggio

Thanks @jun for your helping. I’ve tested this code with multiple div and it’s hiding only the div that it contains the button that i’ve clicked. I wish you a great day! 🙂

Comment posted by Vitto Alloggio

Hi, I’ve already tried this before but it’s not what I’m looking for. This hide the button that i’ve clicked and not the div that It contains the buttton..

Comment posted by Sachin Sanchaniya

I updated my answer as per your requirement.

Comment posted by Vitto Alloggio

How can i run this after $(document).ready(function(){ without hiding all the divs that they contain the class dropdown but only the div that i select by button?

Comment posted by Vitto Alloggio

Ok i’ve fixed with a cicle for and var i. 😛

Comment posted by Rob Moll

Did you mean to write:

By