I have one (for me) strange problem.
I have pop under that open one url. i need to make when user click on some flashplayer (who is in div)
I put javascript code
<script type="text/javascript">
$("player").click(myfunc());
</script>
<script type="text/javascript">
document.getElementById('player').addEventListener('click', myfunc(), false);
</script>
But there is problem.. this not work on click (when user click on #player), this work when user load page ( onload ) and i dont need that, i need on click to start function…
Where is the problem?
Firstly, you appear to be missing the
#character in your jQuery selector (I’m assuming it’s meant to be an ID selector because you also gave an example usinggetElementById), so it’s currently looking an element calledplayer, rather than an element with ID “player”.Secondly, you don’t want to execute the
myfuncfunction when you pass it to theclickfunction. Instead, you want to pass a reference to the function (note the lack of parentheses):The same is true for your second example, but you are right in that when using
getElementByIdyou pass in the string without the#character: