0

I'm sure there is a simple solution to this, but I cannot seem to figure it out. The 'click' does not want to trigger on the Follow button. Also, trying to do this without using jQuery.

var followBtn = document.getElementById("followBtn");
followBtn.addEventListener('click', followed);
function followed(event) {
    var followPars = document.getElementsByClassName("sm-par followed");
    event.preventDefault();
    for(var i=0; i<followPars.length; i+=1) {
        followPars[i].style.display = "inline-block";
        followPars[i].style.marginTop = "0px";
        followPars[i].innerHTML = "Sed vel sem felis.";
    };
};
<div id="main-container">
    <div class="bg-img">
        <img src="images/cover-banner.png" alt="Profile Banner Image"/>
    </div>
    <div class="icon-button">
        <div class="icon">
            <img src="images/profile-image.png" alt="Profile Logo Image"/>
        </div>
        <div class="button">
            <a id="followBtn" class="btn" aria-label="Follow Us Button">Follow</a>
        </div>
    </div>
    <div id="main-content">
        <h1>Lorem Ipsum</h1>
        <p>Sed ultrices sem elit. Integer gravida sapien in maximus auctor. Proin quis urna mauris. Pellentesque maximus at tellus eu ultrices. In vitae massa tincidunt, elementum nunc nec, pellentesque lectus. Aliquam placerat nisi risus, sit amet aliquet dui accumsan eu. Maecenas id urna aliquet, pellentesque ex at, gravida purus.</p>
        <p class="sm-par">Curabitur ac augue fringilla felis varius convallis.</p>
        <p class="sm-par followed"></p>
    </div>
</div>
ibrahim mahrir
  • 28,583
  • 5
  • 34
  • 61
intaglioman
  • 167
  • 1
  • 2
  • 8

1 Answers1

0

I found the solution after the code snippet was added to the code (thanks to Ibrahim Mahrir) and it has nothing to do with the javascript.

The style on the button needed to include a z-index: 1; to sit on top of the container layer to be clickable.

intaglioman
  • 167
  • 1
  • 2
  • 8