Search Results

Search found 1 results on 1 pages for 'user3700824'.

Page 1/1 | 1 

  • How do I debug JavaScript .onlick event?

    - by user3700824
    I'm learning JavaScript but seem to be having a problem. I have a piece of code that is executed when the page is fully loaded. The function then gathers all the button elements on my HTML page. From here I loop through getting each button's title attribute and then assign an onclick event to the button that is equal to a function that writes to the console.log with the title. I have tried various ways of doing this but it is not working. Here is the JavaScript code that I'm working with. Currently all it does is loop through calling the function and logging the tile to the console.log, but this is not supposed to happen. Each time I click the button it should call the function with its title and log that. window.onload = myPageIsReady; function myPageIsReady(){ var myList = document.getElementsByTagName("button"); var myTitle = []; for(var i = 0; i < myList.length; i++){ myTitle[i] = myList[i].getAttribute("title"); myList[i].onclick = getMyTitle(myTitle[i]); }; function getMyTitle(myTitle){ console.log(myTitle); }; };

    Read the article

1