1

So I have an HTML anchor element and I'm trying to set the value of the href attributes using JavaScript but it's returning some error that setAttribute is not a function.

Here's the HTML part below:

 <section id="ftop">
    <a href="sendemailtome" id =" " class="m0a7i11l"> 
 </section>

And here's the JavaScript code:

  var to="To:"; 
  var mAdd ="network"; 
  var aTS="@"; 
  var emAd="keleos"; 
  var pRo="mail"; 
  var dSubj = "?subject=Feedback;"; 
  var emAddr="gmail.com"; 
  var MailAddr = pRo+to+emAd; 
  var dMes="&body=Hello, Kind'ly see feedback below; "; 
  var MailAddrS =mAdd +aTS+ emAddr +dSubj; 
  var complEm = MailAddr + MailAddrS +dMes; 

  var eMail = document.getElementsByClassName("m0a7i11l").setAttribute("href", complEm);

Kindly note that I expected the href value in HTML to be replace with the new value from JS. (I.e href = "mailto: keleosnetwork@gmail.com")

I don't want to do it directly using HTML like href="mailto: keleosnetwork@gmail.com"

  • Yes, it solved the problem. But I'm still wondering why the setAttribute method does not work. Can someone clarify why? – KeleosWilliam Apr 03 '20 at 19:58

0 Answers0