Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opening pdf links in new window with jQuery

Tags:

jquery

This is probably VERY simple and silly, but I am trying to use jQuery to open all pdf's in new windows. I used the code below and get this error:

uncaught exception: Syntax error, unrecognized expression: [href$=.pdf]

I am being a nitwit, I am sure, any help would be appreciated.

Note: I subbed in jQuery for $ because I am using Wordpress.

<script type="text/javascript">
jQuery(function() {
jQuery("a[href$=.pdf]").click(function() {
window.open(this.href);
}); 
}); 
</script>
like image 418
user10210 Avatar asked Nov 14 '11 18:11

user10210


1 Answers

Try this:

jQuery(function($) {
    $('a[href$=".pdf"]').attr('target', '_blank');
}); 
like image 60
ThiefMaster Avatar answered Nov 18 '22 05:11

ThiefMaster