I am trying to change html href attribute variable value ?post=55 to ?post=44 with button click while not changing other URL variable(thread=7) using jQuery, but don't know how.
HTML
<button class="button">button</button>
<a href="posts.php?thread=7&post=55" class="post-link">Post</a>
JAVASCRIPT
$('.button').on('click', function() {
$("a").attr('href','posts.php?post=44') // this does not work because it removes ?thread=7
$("a").attr('href','posts.php?thread=7&post=44') // this also does not work because ?thread=7 is just a placeholder. I don't know what actual thread number is going to be.
});
This is what I have
<a href="posts.php?thread=7&post=55" class="post-link">Post</a>
This is what I want when clicking button
<a href="posts.php?thread=7&post=44" class="post-link">Post</a>