Add target to anchor tags with jquery

admin

Administrator
Staff member
I have an html snippet:

Code:
<div class="wc-social-login form-row-wide">
    <a href="http://www.example.com/wc-api/auth/twitter/? return=http://www.example.com" class="button-social-login button-social- login-twitter"><span class="si si-twitter"></span>Connect with  Twitter</a>
    <a href="http://www.example.com/wc-api/auth/facebook/?return=http://www.example.com" class="button-social-login button-social-login-facebook"><span class="si si-facebook"></span>Connect with  Facebook</a>
</div>

I need to add a target element to the anchor tags, this is inside wordpress.

I tried this with jquery:

Code:
jQuery(document).ready(function ($) {
    $('.wc-social-login form-row-wide a').each(function () {
        $(this).attr('target', '_blank');
    });
});

Any inputs on how to add a target attribute to both the tags inside the div will be very helpful.