javascript - Add text to downloads link via jquery -


this question has answer here:

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

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -