Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to Fix Javascript Code for Getting Href Content of a Link

    • 0
    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 572
    Answer it

    I am trying to get the href content of a link that i click on with the class of sessionBtn.

     

    Here is my code: 

    $('.sessionBtn').on('click', function (e) {
      e.preventDefault();

     var url_string  =  document.getElementsByClassName("sessionBtn").href;

     document.getElementById("demo").innerHTML = "document id: "+url_string;

     });

     

    But i got an error of undefined.

    But when i get the elements by ID it works. 

 1 Answer(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: