Google Tag Manager, How to return a class inner text if a parent tag does not have class

I have the following html code:

<li class="ais-RefinementList-item ais-RefinementList-item--selected">
 <div><label class="ais-RefinementList-label">
  <input type="checkbox" class="ais-RefinementList-checkbox" checked="" value="Software">
  <span class="ais-RefinementList-labelText">Software</span>
  <span class="ais-RefinementList-count">264</span></label></div></li

I want to do the following: if the class ais-RefinementList-item–selected” exists to not do anything and if it does not exists then to continue to extract the ais-RefinementList-labelText.

I used the following function which worked to always get the labeltText even if the click element was on the count to always get the text value for the analytics and it works fine:

function () { return {{Click Element}}.parentNode.lastChild.previousSibling.innerText }

Therefore i want to have this function run only if ais-RefinementList-item–selected” does not exist in the li as it is added when a checkbox is clicked on the website search filters.

Another thing i noticed was that when the checkbox is not clicked, checked does not appear.

checked=""

I tried doing a DOM ELEMENT trigger variable but it then stopped counting when multiple filters were checked.