Way to open a clicked link of a certain class in a new tab in TamperMonkey
12:46 12 Nov 2025

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.

javascript html css