Home > OS >  Add hyperlink to WordPress Accordion Title Using jQuery
Add hyperlink to WordPress Accordion Title Using jQuery

Time:11-02

I have an accordian on a page I am building at https://therussellcons.wpengine.com/services/ and I am trying to add a hyperlink to the "Train the Trainer" title, but can't seem to figure it out. The title has an empty href since it is used to fire the opening of the accordion, but I need this particular accordion to link to an external url. I've tried many different things, but below is what I've tried last with no luck.

jQuery(document).ready(function(){
    jQuery("#elementor-tab-title-1832").click(function(){
            $("a.elementor-accordion-title").attr("href", "https://www.test.com");
    });
});

CodePudding user response:

If the number of tab titles is a lot and differents, use a variable like redirectUrl.
Then handle the click event on link by js:

var redirectUrl = "#";
jQuery(document).ready(function(){
    jQuery("#elementor-tab-title-1832").click(function(e){
          redirectUrl = "http://test.com";
    });
    //Others tab-title-xxxx click events
    //...
    //...

    jQuery("a.elementor-accordion-title").click(function(e){
          e.preventDefault();
          window.location.href = redirectUrl;
    });
});

CodePudding user response:

You can put the onclick attribute in your a tag, like this:

<a href="" onclick="window.open('http://test.com', '_blank')">...</a>
  • Related