Problem with a "contains" jQuery selector on href

Bronze Contributor
Bronze Contributor

I've got a link like <a href="/blah/Blech/Foo/120987/"> and I'm trying--with a "jQuery onHandler (1.7 and above)"--to select it on mouse down. The minor issue being that the final digits in the href fluctuate, so I want any As w/ HREFs containing '/blah/Blech/Foo/'.

 

The jQuery selector I'm using in TealiumIQ is $('a[href*=\"/blah/Blech\/Foo/\"]') - and this works in the chrome dev console when tested like this:

 

$('a[href*="/blah/Blech/Foo/"]').on('mousedown',function(){ console.log('that element is clicked') ; })

but somehow the quotes get messed up - once published, the chrome console comes back after the click with:

Uncaught Error: Syntax error, unrecognized expression: $("a[href*="/blah/Blech/Foo/"]")

whether or not I escape the single quotes, or the double quotes, or both. That is not the way I set up the selector. Any ideas?

2 REPLIES 2

Problem with a "contains" jQuery selector on href

Tealium Employee

@John

 

So I have just tried the same thing:

 

jquery.png

 

Just to confirm you only need the select, and not the full jQuery snippet.

 

Adrian

Ask me anything Tealium related or TypeScript/JavaScript, or NodeJS.
Please remember to mark solutions as accepted for future searchers.

Problem with a "contains" jQuery selector on href

Bronze Contributor
Bronze Contributor
Right on. Thanks Adrian!
Public