I would like to prepend "Download a PDF of " to any hyperlinks, linking to PDF files. Currently I'm able to prepend that exact text, but it prepends it to the hyperlink text. I would like it to reside outside of the hyperlink element, like so: Download a PDF of [hyperlink with text]
This is the code I'm using now:
jQuery('a[href$=.pdf]').prepend('Download a PDF of ');
Have you tried before?
jQuery('a[href$=.pdf]').before('Download a PDF of ');
The other selectors that have been provided in answers are wrong, as of today anyway. jQuery will complain:
Uncaught Error: Syntax error, unrecognized expression: a[href$=.pdf]
The right way to select the anchor is:
jQuery('a[href$=".pdf"]');
Note the quotes around .pdf
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With