- TLC Home Home
- Discussions Discussions
- Documentation Documentation
- Knowledge Base Knowledge Base
- Education Education
- Blog Blog
- Support Desk Support Desk
01-11-2016 02:11 PM - edited 01-11-2016 02:12 PM
I have been setting up JQuery Onhandlers using "jquery selector" alt tag names for images. I noticed tracking will not work if an alt tag name has special characters. Is there a way to fix this issue without changing the alt name of the image?
01-12-2016 09:49 AM - edited 01-12-2016 10:27 AM
Hi @jonathan_mantil,
Try adding a backslash before the special character in the alt tag e.g. [alt="jon\'s alt tag"]
Hey @jonathan_mantil
In order to make sure that the resulting utag.js file is syntax error-free, the jQuery extension will only allow one type of quotes to be used in the selector field, which makes it tricky in cases where you really do want to use a single quote/apostrophe in your selector.
There is a workaround for this, which is to substitute the actual quote character for its unicode representation. This doesn't make for very readable code, but unfortunately there is no other option at present, and it's not something that you should need to do very often. The unicode representation in JavaScript for a single quote is \u0027. Here's an example:
To represent "Dave's wooden ladders", you would do:
alt="Dave\u0027s wooden ladders"
When this gets evaluated in your browser, your browser will execute the unicode command and will see this as the original text "Dave's wooden ladders".
For reference in case you ever need it, the unicode representation in JavaScript for a double quote is \u0022
I hope this helps.
Craig.
04-13-2016 01:36 PM - edited 04-13-2016 02:06 PM
Hi @christina_schel! For some reason this procedure is not working for me.
04-13-2016 01:37 PM - edited 04-13-2016 02:08 PM
Hi @craig_rouse! I tried applying this method and it's not working for me.
Hi!
The alt tag is What's New in Suits!
Hey @jonathan_mantil!
I just set up a demo page showing this in action, and it does work, but you need to be careful about the types of quotes you are using. It seems that the screenshot in my previous answer was incomplete. Here's a new screenshot:
Here is a demo page showing it in action:
http://solutions.tealium.net/hosted/cpr/suits.html
If you click on the "Suits" button at the top of the page, this will trigger the jQuery onHandler extension, which in turn triggers an alert to show that you have clicked the button.
The full code for the jQuery handler, assuming it is an anchor (<a>) element, is:
a[alt="What\u0027s New in Suits!"]
\u0027 represents the single quotation mark in unicode.
Let me know if you have any trouble implementing this.
Thanks,
Craig.
04-15-2016 06:00 AM - last edited on 04-15-2016 10:58 AM by kathleen_jo
Copyright All Rights Reserved © 2008-2023