0

My problem is when I change the href attribute via javascript the new href appended into website URL the main link before change using jquery

after i change href

 $(".buttonSec").prop("href", "my_wanted_href");

the URL be like

page URL after the change on the buttonSec

what I want is how to make this url do not append the link using jquery

mujuonly
  • 11,370
  • 5
  • 45
  • 75
  • 1
    Possible duplicate of [How to change the href for a hyperlink using jQuery](https://stackoverflow.com/questions/179713/how-to-change-the-href-for-a-hyperlink-using-jquery) – artomason Mar 14 '19 at 11:55
  • i don't want change the href attrebut i already did what i want is affter changing this attrebute make the page url like it is even when i click on the button that have this attrebute $(".buttonSec").prop("href", "my_wanted_href"); – asmaa abdelatty Mar 15 '19 at 11:31

1 Answers1

0

Try using attr property instead of prop try the code below.

$(document).ready(function(){
  $("button").click(function(){
    $("#stack").attr("href", "https://google.com");
  });
});
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>

<p><a href="https://www.stackoverflow" id="stack">STACKOVERFLOW</a></p>

<button>Change href Value</button>

<p>Mouse over the link (or click on it) to see that the value of the href attribute has changed.</p>

</body>
</html>
Darsh khakhkhar
  • 666
  • 5
  • 15