0

I want to hide the link field button when the value of the button equals to 'Work Order' see the image below.

enter image description here

My HTML code:

enter image description here

I tried this $("li[data-label='Work Order']").hide() but didn't worked.

1
  • Do you want the <a> to always be hidden when that's the data attribute, or do you only want it to occur conditionally? Commented Feb 1, 2020 at 8:11

1 Answer 1

2

The li is not the same element as the one with the data-label attribute. If you want to hide the <a> inside, use the selector string a[data-label='Work%20Order']:

$("a[data-label='Work%20Order']").hide()
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<a data-label="Work%20Order">link</a>

You do need to use the %20 inside the selector.

If you want to always hide such an element, you can achieve this with CSS alone - no need for jQuery or any Javascript at all. Use the same selector string plus display: none:

a[data-label='Work%20Order'] {
  display: none;
}
<a data-label="Work%20Order">link</a>

If you want to hide the whole <li> container when one of its children has such an attribute, then select each of those elements with jQuery and call .parent() on it:

$("a[data-label='Work%20Order']").parent().hide();
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul>
  <li>
    <a data-label="Work%20Order">link</a>
  </li>
  <li>
    <a>link 2</a>
  </li>
  <li>
    <a data-label="Work%20Order">link 3</a>
  </li>
</ul>

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

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.