0

My links looked like:

<a href="xxx.pdf">linktext</a> 

I want to add some html to the a tag if there is a .pdf.

I've found this:

jQuery('a[href$=".pdf"]').each(function() { .... }); 

But I dont know what I have to add to get this:

<a href="xxx.pdf" target="_blank" class="download">linktext</a> 
1
  • class is done ... jQuery('.entry-content a[href$=".pdf"]').each(function() { jQuery("a").addClass("test"); }); Commented Oct 27, 2017 at 10:15

1 Answer 1

3

Add the attribute using .attr() method.

jQuery('a[href$=".pdf"]').addClass('download').attr('target', '_blank')
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <a href="xxx.pdf">linktext</a>

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.