2

I'm in the process of building a very simple blogging tool for my personal website. One feature I'm working on is a comments section. Next to each blog post on my website is a button that, once clicked, shows the comments for that particular blog post.

The comment buttons are created dynamically in javascript with

  var commentLinks = document.createElement("INPUT");
        commentLinks.setAttribute("type", "image");
        commentLinks.setAttribute("src", "linkredacted");
        commentLinks.setAttribute("id", "commentButton"+i);
        commentLinks.addEventListener("onmouseover", function(){
    changeSrc(commentLinks);
}, false);

The problem I am facing is that the mouseover event never fires. I have verified that my URL paths are correct and that the original button is created successfully, but no matter what I try I cannot get the button to resize after the mouseover event. Here is the changeSrc function that the code above calls:

function changeSrc(commentLinks)
{
  commentLinks.src = "linkredacted";
}

I have also tried using setAttribute which did not work, as well as placing the entirety of the function call in one anonymous function, which also did not work. Any help would be greatly appreciated

2
  • 1
    Just use a background-image and CSS. It's 2020, not 2000. :P Commented Jan 26, 2020 at 22:08
  • The purpose of building project from scratch is to push myself to learn Javascript fully so using CSS is not the goal. Commented Jan 26, 2020 at 22:15

1 Answer 1

2

Use mouseover. Not onmouseover commentLinks.addEventListener("onmouseover", function(){ should be commentLinks.addEventListener("mouseover", function(){

Sign up to request clarification or add additional context in comments.

1 Comment

See response. Thank you for the answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.