0

I am working on a music streaming website and i have this code and i want to know how to prevent page from changing song after i click on the href link

$.post("includes/handlers/ajax/getAlbumJson", {albumId: track.album}, function(data){
                var album = JSON.parse(data);

                $(".albumLink img").attr("src", album.artworkPath);
                $(".albumLink img").attr("onclick", "openPage('album.php?id=" + album.id + "')");   
                $(".trackName span").attr("onclick", "openPage('album.php?id=" + album.id + "')");
                 $(".trackName a").attr("href", "album.php?id=" + album.id + "");

            });

    <span class="trackName dark-primary-hover">
      <a href="" role="link" style="pointer-events: auto;"></a>
    </span>
Liam
  • 27,717
  • 28
  • 128
  • 190
naija
  • 19
  • 1
  • 6

1 Answers1

1

You should be able to just do:

$(".trackName a").on('click', function(){
return false;
});

Here's a working example:

$(".trackName a").on('click', function(){
    return false;
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div class="trackName">
<a href="https://stackoverflow.com/">Click Me</a>
</div>