based on this question and answer:
This very helpful method provided by Brock Turner enables this for links (anchor tags) containing the string cars :
// ==UserScript==
// @name NOT an AutoClicker, per question text
// @include https://example.com/*
// @require https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js
// @grant GM_addStyle
// ==/UserScript==
var TargetLink = $("a:contains('cars')");
if (TargetLink.length)
TargetLink.attr ('target', '_blank');
This works flawlessly and is very useful, but I want to select links by class (they could have any anchor text).
The HTML looks like this:
In Summary and My attempt
I want to replicate var TargetLink = $("a:contains('cars')"); but instead affect clicked links with class="a-link-normal"
I tried using .a-link-normal (I read that you must put a dot in front for a class name) in place of var TargetLink = $("a:contains('cars')");
I also tried using it with single quotes ' and without any quotes at all—without success.
Privacy & Cookie Consent
We use cookies to ensure the best experience on our website. This includes analytics, personalization, and marketing purposes. Some cookies are essential for the website to function properly.
By clicking "Accept", you consent to our use of cookies. You can read more about how we use cookies and how you can change your preferences in our Privacy Policy.