Home » Jquery » php – Changing all links with jquery

php – Changing all links with jquery

Posted by: admin February 22, 2020 Leave a comment


I want to take things from another site and add href’s a link. But my JQuery code just took the first href and change every hrefs’ with that.

The code takes a table and tag. I just want to add a link in front of href.
I mean first href is like “example/example1” and I want to change it like “https:example.com/example/example1”.

PHP cUrl code:


$curl = curl_init();


$sonuc = curl_exec($curl);

preg_match_all('@<td class="subtitle1">(.*?)</td>@si',$sonuc,$info);
$info = $info[0];
echo '<ul class="movie-name">';
for($i=0; $i < count($info);$i++){
    echo '<li class="content">';
    echo $info[$i];
    echo '</li>';

echo '</ul>';


And JQuery code:

var href = $(".alert-link").attr("href");
$(".alert-link").attr("href", "https://planetdp.org"+href);
How to&Answer:

I took the page with cUrl to html, then I use this script and change the hrefs’:

(function() {
    'use strict';

    $('.list_main > .list a').each(function(){
        $(this).attr("href", "https://planetdp.org" + $(this).attr("href") );


Tested working good. Hope this help you.

$('a').each(function() {
  var value = $(this).attr('href');
  $(this).attr("href", "https://planetdp.org"+href);