-1

I want the bootstrap class of the link to be changed when a link is clicked .

<a href="link1"> link to be clicked </a>
<a href="link2" id="x" name = "x" class="btn btn-info btn-sm disabled">link to be changed</a>
PrakashG
  • 1,642
  • 5
  • 20
  • 30
issam
  • 45
  • 6
  • 2
    Links do not have a `disabled` attribute, that is a thing for form controls. Search terms like “javascript disable link” would have easily led you to https://stackoverflow.com/questions/5376444/how-do-i-disable-a-href-link-in-javascript – 04FS Feb 13 '19 at 11:23
  • @04FS i'm using bootstrap – issam Feb 13 '19 at 11:26
  • 1
    And what does that have to do with anything, regarding this particular question? – 04FS Feb 13 '19 at 11:28
  • @04FS using bootstrap we can add a class with disabled attribute, – issam Feb 13 '19 at 11:32
  • @04FS well i can reform the question like that : how to change the class of a link after another one is clicked – issam Feb 13 '19 at 11:33
  • Well you know how to react to the click happening already, so this would then boil down to, _“how do I add/remove/change the class(es) of an element with JavaScript”_, and that, again, should be rather easy to research. – 04FS Feb 13 '19 at 11:34
  • @04FS thanks , i will change the question – issam Feb 13 '19 at 11:35
  • _“using bootstrap we can add a class with disabled attribute”_ - please link to the documentation of what exactly you are referring to here. – 04FS Feb 13 '19 at 11:36

2 Answers2

0

Presuming you don't want the link to be clicked, you could always just hide it using javascript.

<a href="#" onClick='document.getElementById("2").style.display = "none"'>link to be clicked </a>
<a href="#" id="2" name = "2">link to be disabled</a>

EDIT: Just noticed you updated your question, you can try this it adds the disabled class to the link.

<a href="#" onClick='document.getElementById("2").classList.add("disabled")'>link to be clicked </a>
<a href="#" id="2" name = "2">link to be disabled</a>

You can read more about the disabled class on the bootstrap documentation here: https://getbootstrap.com/docs/4.0/components/buttons/#disabled-state

0

You can change your code as below, it will help you to achieve your requirement easily.

<html>
<head>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.0/css/bootstrap.min.css"/>
</head>
<body>
 <a href='#' OnClick = "document.getElementById('2').removeAttribute('Class');document.getElementById('2').setAttribute('Class','btn btn-info btn-sm disabled');" > link 
   to be clicked </a>
   <a href="link2" Class='btn btn-info btn-sm' id="2" name = "2"> link to be disabled </a>
</body>
</html>