How to hide elements in Jira using CSS or JavaScript

お困りですか?

アトラシアン コミュニティをご利用ください。

コミュニティに質問

プラットフォームについて: Server および Data Center のみ。この記事は、Server および Data Center プラットフォームのアトラシアン製品にのみ適用されます。

Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Fisheye および Crucible は除く

このページの情報は、Jira アプリケーションのカスタマイズに関連しています。アトラシアン サポートの提供内容にカスタマイズは含まれていないため、アトラシアン サポートでは、このページで記載されている手順に対するサポートを保証できません。この資料は情報提供のみを目的としており、記載内容は自己責任の下で行っていただく必要があります。

また、ファイルの直接変更によって行われるカスタマイズは、アップグレード プロセスには含まれない点にご注意ください。このような変更は、アップグレード後のインスタンスで手動で再適用する必要があります。

目的

As a Jira admin, you may need to hide HTML elements such as links or buttons to prevent users from accessing a functionality. 

ソリューション

For each element we want to hide, we need it to have an ID. The element ID can be found as follows in Google Chrome: 

  1. Right-click on the element 
  2. Choose Inspect
  3. Find the element you want to hide, see the screenshot below as an example:
    1. An element with an ID:  
    2. An element without an ID:
       

  4. Once you have the HTML element's ID or tag/class, hide it by adding the following code snippets to the Jira announcement banner

    Please be mindful that tempering with modifying CSS layout in flight might cause Jira to become completely inaccessible to users; That is, the login page might stop operating properly, or certain page elements in Jira will no longer be accessible, such as for example not being able to access the Announcement banner configuration page to remove the faulty code. If that becomes the case please follow the below article to remove the announcement banner via a direct database update:

    Remove the Jira server announcement banner through the database

Using CSS

As an example, the code below will hide all links allowing users to change project roles or user to role assignments in all pages of Jira. Note the CSS below uses the element ID:

<style type="text/css">
#project-config-webpanel-summary-people {
    display: none;
}
#roles-add-users-button {
    display: none;
}
#view_project_roles {
    display: none;
}
</style>

If the element you need to hide doesn't have an ID, you can use the element tag in combination with one or more classes. For example, to hide the "Add customers" button from the Service Management portal, use:

<style type="text/css">
button.aui-button.js-invite-customers {
    display: none;
}
</style>

Notice, sometimes there's an additional css that can still overwrite your code and the tweak will not work; to prevent this you can try adding !important statement that will prevent further overwriting of css style with another css. If that becomes the case, the code will look like this:

<style type="text/css">
button.aui-button.js-invite-customers {
    display: none !important;
}
</style>


Using JavaScript

As an example, the code below will only execute if the page URL has /plugins/servlet/project-config/ and will hide the links allowing users to change project roles or user to role assignments.

<script type="text/javascript">
window.onload = function() {
  if(document.URL.indexOf("/plugins/servlet/project-config/") >= 0){ 
    // Hide left hand side link
    document.getElementById('view_project_roles').style.display = 'none';
    // Hide right hand side element
    document.getElementById('project-config-webpanel-summary-people').style.display = 'none';
  }
};
</script>
  • Only use JavaScript if you intend to hide elements on some pages but not others.
  • Any error in the JavaScript code because of the absence of an element from a given page will break the entire execution.
  • Saving the announcement banner may result in a browser error that can be ignored.

NOTE:

8.7 and later a setting was added with the default shifted to OFF as covered in:

Make sure to set the global setting to enabled as covered in the following documentation to use scripts in the field descriptions

Enable HTML in custom field descriptions and list item values:

カスタム フィールドの説明やリスト項目の値に HTML を追加することを許可します。

Default: OFF (recommended for security)  

Last modified on Mar 10, 2021

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.