Feature Box Icon Link - New Tab

Hi,
I used the following code to get the icon of my feature box to link to the url set in the feature box.
jQuery( document ).ready( function($){
$(".class-on-item-around-feature-box").each( function( ) {
var link_value = $($(this).find(“a”).get(0)).attr(“href”);
var link_element = ‘’;
$(this).find(’.x-feature-box-graphic’).wrap(link_element);
});
});

How can I change the code to make the link open in a new tab?

Thank you!

Hi There,

Thanks for writing in!

Can you please try this code if that works.

jQuery( document ).ready( function($){
$(".class-on-item-around-feature-box").each( function( ) {
var link_value = $($(this).find("a").get(0)).attr("href").attr('target', '_blank');
var link_element = '';
$(this).find('.x-feature-box-graphic').wrap(link_element);
});
});


Hope this works.
Or you can check this for more help.

Thanks

No that didn’t work. Now it doesn’t link at all.

Hi There,

Please update the code to this:

jQuery( document ).ready( function($){
  $(".class-on-item-around-feature-box").each( function( ) {
    var link_value = $($(this).find("a").get(0)).attr("href");
    var link_element = '<a target="_blank" href="' + link_value + '"></a>';
    $(this).find('.x-feature-box-graphic').wrap(link_element);
  });
});

For more information about the _target attribute, please take a look at this:

https://www.w3schools.com/tags/att_a_target.asp

Hope it helps :slight_smile:

That’s perfect, thanks!!

Glad it worked.

Cheers!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.