skip to Main Content

My footer elements are loading with dynamic id’s. I used as follows

$(document).ready(function () {
 $("[id^='footer']").click(function (evt) {
     evt.preventDefault();
     if (window && window.siteConsent && window.siteConsent.manageConsent) {
         window.siteConsent.manageConsent();
     }
     console.log(evt.target.id)
 });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>

<a href="level2Link.NavLink" class="f-link managecookieShow" id="footer-nav-ManageCookies one1" aria-label="level2Link_AriaLabel">
    One
</a>
<br/>
<a href="level2Link.NavLink" class="f-link managecookieShow" id="footer-nav-ManageCookies two2" aria-label="level2Link_AriaLabel">
    two
</a>

Actually it is not working. When i am using ^ this symbol is for getting contains of the id name. But it did not helped me.

2

Answers


  1. You can use "Attribute Contains Selector" [name*="value"]

    I think this symbol "^" cannot help you to select the component that its id contains substring.
    But you can use "*" symbol to select that component.
    For example: $("a[id*='footer']")

    $(document).ready(function () {
     $("a[id*='footer']").click(function (ev) {
         ev.preventDefault();
         if (window && window.siteConsent && window.siteConsent.manageConsent) {
             window.siteConsent.manageConsent();
         }
     });
    });
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
    
    <a href="level2Link.NavLink" class="f-link managecookieShow" id="footer-nav-ManageCookies one1" aria-label="level2Link_AriaLabel">
        One
    </a>
    <br/>
    <a href="level2Link.NavLink" class="f-link managecookieShow" id="footer-nav-ManageCookies two2" aria-label="level2Link_AriaLabel">
        two
    </a>
    Login or Signup to reply.
  2. $(document).ready(function () {
     $(document).on("click", "[id^='footer']", function (ev) {
        ev.preventDefault();
        if (window && window.siteConsent && window.siteConsent.manageConsent) {
            window.siteConsent.manageConsent();
        }
     });
    });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search