javascript - Add text to downloads link via jquery -
this question has answer here:
- how update (append to) href in jquery? 4 answers
i want know if possible via jquery since can't add in markup:
i want add download.php?file=
url (links change can't replace whole href
):
<a class="boton" target="_blank" href="http://www.test.com/wp-content/uploads/2014/11/prueba-es.pdf">download</a>
so link this:
<a class="boton" target="_blank" href="http://www.test.com/wp-content/uploads/2014/11/download.php?file=prueba-es.pdf">download</a>
any ideas?
this should work
$('.boton').each(function (i) { var hreforig = $(this).attr('href'); var segments = hreforig.split('/'); var file = segments.pop() var hrefnew = hreforig.replace(file, 'download.php?file='+file); $(this).attr('href', hrefnew) })
@ariel_556 answer work, 1 matches how described url
Comments
Post a Comment