web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Javascript Conditional...
Power Automate
Unanswered

Javascript Conditional Logic - How can I click a button if a span has a particular sibling?

(0) ShareShare
ReportReport
Posted on by 65

 

 

<a class="item">
<span class="item_label">BIG_1</span>
<span class="acitve-high">...</span>
</a>
<a class="item">
<span class="item_label">BIG_2</span>
<span class="acitve-low">...</span>
</a>


<a class="button-high">...</a>
<a class="button-low">...</a>

 

 

 

How can I achieve the following actions using jquery function?

If the span containing text "BIG_1" has a sibling with class name "active-high" then click button with class name "button-high"
else if span containing text "BIG_1" has a sibling with class name "active-low" then click button with class name "button-low"


In the HTML, the span with text BIG_1 currently has a sibling with class name "active-high". I want the code to always check if this is true and then click a button with class name "button-high" if so. The website is dynamic and so the span with class name "active-high" sometimes automatically changes to "active-low". So, I want the code to click the button with class name "active-low" instead every time this change occurs.

Please note: More than one span has the class name "item_label" so I can't use the class name to identify the span with text BIG_1. Also, I can't use its position either because that changes automatically from time to time as well.

  • AS-06081019-0 Profile Picture
    1,738 Super User 2024 Season 1 on at

    @donaldekpe Could you please share the website URL?

  • Henrik_M Profile Picture
    2,021 Super User 2024 Season 1 on at

    Add two UI elements:

    a:contains(BIG_1) > span[class="active-high"]​
    a:contains(BIG_1) > span[class="active-low"]​

     This will find the span element with classes "high/low-active" within an a containing the text "BIG_1"

     

    Add UI elements:

    a[class="button-high"]​
    a[class="button-low"]​

     

    Then add your If web page contains conditional actions. I think you can edit the second If into an Else if if you copy the actions into notepad, then add ELSE in front, before copying back into PAD.

  • donaldekpe Profile Picture
    65 on at

    That is exactly what I have in the flow already. I want to convert them to javascript because they are so many of them in the flow and the UI Element attached to each is seriously weighing and slowing down PAD. I just believe using javascript instead will speed things up, I may be wrong though.

  • donaldekpe Profile Picture
    65 on at

    Would have loved to but it is kind of a private website and you need to have a paid account to access it.

  • Henrik_M Profile Picture
    2,021 Super User 2024 Season 1 on at

    Aahhhh... Didn't read the JavaScript part 🤐

     

    This seems useful: https://stackoverflow.com/questions/31044/is-there-an-exists-function-for-jquery 

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Automate

#1
Mohsin Ali Profile Picture

Mohsin Ali 423

#2
11manish Profile Picture

11manish 308 Super User 2026 Season 2

#3
M Bilal Khan Profile Picture

M Bilal Khan 177

Last 30 days Overall leaderboard