0

I was able to add the attribute tab index using the id like this:

 $("#idname").attr("tabindex", "0");

but when I tried it with class

 $(".classname").attr("tabindex", "0");

it doesn't work

2
  • "I want to remove a button thats within a couple of divs" - and what's not working? What's your question? Kudos for adding your code, although the .dashboard-container and #multi-reports both appear to be missing from your html, but it's not clear what you need help with. Commented Feb 6, 2020 at 18:12
  • That button is only in one div (not a couple). If you intend for it to be in more than one div you'll need to ensure it has a unique id (duplicates are not allowed). Consider using a class instead. Commented Feb 6, 2020 at 18:18

3 Answers 3

1

Use below code. I am highlighting container in grey, click anywhere on that grey area and button will be removed.

$( document ).ready(function() {
  $(".container").on("click", function(e) {
        $("#go-back").remove();
  })
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="container" style="background:grey">
  <div class="reports">
    <div class="header">
      <button id="go-back">
          <i class="fas fa-chevron-left" aria-hidden="true"></i>Go Back
      </button>
    </div>
  </div>
</div>

Sign up to request clarification or add additional context in comments.

Comments

0

What you have should work:

$(function() {//document ready
  $(".dashboard-container").on("click", "#multi-reports", function(e) {
    $("#go-back").remove();
  })
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="dashboard-container">
  <button id="multi-reports">
       Click to remove
</button>
</div>


<div class="reports">
  <div class="header">
    <button id="go-back">
        <i class="fas fa-chevron-left" aria-hidden="true"></i> Go Back
      </button>
  </div>
</div>

Comments

0

A solution with pure JS: Note the click event is on the multi-reports button and not the div

document.getElementById("multi-reports").addEventListener("click", () => {
    let element = document.getElementById("go-back");
    if(element){
      element.parentNode.removeChild(element);
    }
});
<div class="dashboard-container">
   <button id="multi-reports">
   Click to remove
   </button>
</div>
<br>
<div class="reports">
   <div class="header">
      <button id="go-back">
      <i class="fas fa-chevron-left" aria-hidden="true"></i> Go Back
      </button>
   </div>
</div>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.