0

This is my code:

for(var i = 0; i < 13; i++)
    north.innerHTML += "<div  onclick='remove()' style='display:inline-block; position:relative;'>" + 
                            "<img width='50px' style='cursor:pointer' height='100px'src=path"+player1[i]+".png'/>" + 
                       "</div>";

The problem I'm encountering is in the onclick attribute of the div's I'm inserting. When using onclick='remove()' the script works, but when i change the function to be executed with some other function declared by me it doesn't work.

I initially thought there may be a problem with the function i declared, but it doesn't work even with simple function as:

function example()
{
    prompt('example');
}

Any suggestions? This is a link to the script : https://drive.google.com/file/d/0B44rvU_T40BTVGN2V1RmVWdSS28/view?usp=sharing

  • 4
    Where is the function declared? Post a fuller example. Also you should rethink how you are structuring things. – todinov Nov 26 '15 at 18:14
  • where is which function declared? i'm a beginner in Javascript so excuse my poor Structuring :P the function remove() isthe standard method of javascript object and it executes just fine. the problem arises when i try to call another function declared inside the same js file – Amarildo Likmeta Nov 26 '15 at 18:17
  • @AmarildoLikmeta See my answer, I am sure it will help you – Markus Safar Nov 26 '15 at 18:18
  • Please add a [mcve] to your question (the part that is not working). It's hard to troubleshoot with only pieces of the puzzle - for example, can you add the other function that you are trying to call (the one that fails) – blurfus Nov 26 '15 at 18:19
  • @AmarildoLikmeta Does it work if you declare it like this `window.example = function() {...}`? – rixo Nov 26 '15 at 18:25
  • @rixo 28 does the call to the function in attribute onclick change? – Amarildo Likmeta Nov 26 '15 at 18:27
  • @Teemu but it does work when i call method remove() why is that? how would you suggest to do it with addEvenetListener – Amarildo Likmeta Nov 26 '15 at 18:29

0 Answers0