Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,465,154
Community Members
 
Community Events
176
Community Groups

Can I make a button's text change dynamically on click?

I have stolen a user macro for "Expand All" from this forum, but my users have asked if it is possible to make the text in the button change based on the state of the page.

So it toggles between "Expand" or "Collapse" based on whether the button has been clicked.

This is the macro I have used, but not sure how to change to get dynamic button name:

## Macro title: Expand All
## Macro has a body: N
## Developed by: George Lewe
## Date created: 2014-09-22
## Installed by: George Lewe
## @noparams
<p align="left"><button name="toggleAll" id="toggleAll" type="button" class="aui-button" aria-pressed="false" style="background-color:blue;color:white;font-weight:bold">Expand All / Collapse All</button></p>

<script type="text/javascript">
AJS.toInit(function ()
{
AJS.$('#toggleAll').click(function()
{
var expanded = jQuery(".expand-icon.aui-iconfont-chevron-down").closest("div");
var unexpanded = jQuery(".expand-icon.aui-iconfont-chevron-right").closest("div");
if (expanded.size() > unexpanded.size()) {
expanded.each(function(){ jQuery(this).trigger("click");})
} else {
unexpanded.each(function(){ jQuery(this).trigger("click");})
}
});
});
</script>

1 answer

0 votes
Brittany Joiner Community Leader Jul 21, 2022

@Stewart Eade which button in trello are you trying to change? i could probably make something with PixieBrix that changes the text of the button when its clicked, but to show an example I'd need to know which button you're talking about

Thanks for your response. I managed to work it out and the new code (shown in BOLD) below:-

## Macro title: Expand All
## Macro has a body: N
## Developed by: George Lewe
## Date created: 2014-09-22
## Installed by: George Lewe
## @noparams
<p align="left"><button name="toggleAll" id="toggleAll" type="button" class="aui-button" aria-pressed="false" style="background-color:blue;color:white;font-weight:bold">Expand All</button></p>

<script type="text/javascript">
const btn = document.getElementById("toggleAll");

AJS.toInit(function ()
{
AJS.$('#toggleAll').click(function()
{
var expanded = jQuery(".expand-icon.aui-iconfont-chevron-down").closest("div");
var unexpanded = jQuery(".expand-icon.aui-iconfont-chevron-right").closest("div");
if (expanded.size() > unexpanded.size()) {
expanded.each(function(){ jQuery(this).trigger("click");
btn.innerText = "Expand All";})
} else {
unexpanded.each(function(){ jQuery(this).trigger("click");
btn.innerText = "Collapse All";})
}
});
});
</script>

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events