0

When I use this line

$("#edit-link-1").removeAttr("href");

It disables the link.

Now I want to enable the same link again. So I tried this line, but its kind of not working :(

$("#edit-link-1").addAttr("href",true);

<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.3.1.min.js"> 
</script>

<a href="#" id="edit-link-1">Link1</a>
<script type="text/javascript">
    $("#edit-link-1").removeAttr("href");
    $("#edit-link-1").addAttr("href",true);
</script>

2 Answers2

4

In jQuery the correct way of adding an attribute is:

$("#edit-link-1").attr("href", 'https://www.google.com/');
quirimmo
  • 9,800
  • 3
  • 30
  • 45
0

Also you have another option, depends on wich jQuery version are you working on.

Since v1.6 you can use prop, http://api.jquery.com/prop/

var $link = $("#edit-link-1");
$link.prop('href', 'https://www.google.com/');

Regards

masmerino
  • 957
  • 9
  • 8