Why is my onclick event not registered in Firefox?

I have an event list item onclick. It works in Chrome and Internet Explorer, but not in Firefox. Any suggestions?

<li onclick="alert('test');">test test<br></li>
+5
source share
4 answers

This works great for me in Firefox.

Check this:

  • JavaScript is enabled in your browser.

  • Try adding instructions return false;to your tag.

Or a function like this:

function test() {
    //your code here
    return false;
}
  • Or use this:

<a href="#" onclick="alert('hi');">Link</a>

or

<a href="javascript:void(0)" onclick="alert('hi');">Link</a>

+3
source

I tried to minimize my html code in order to send the full code to simulate an error, as requested by Boris Zbarsky. Then I found my mistake.

I used the marquee shortcut, which is deprecated. Now I will use jQuery instead.

thank

0

In Firefox, the event object is not global. You should access it in script tags, not in html.

onclick works like this

<li id="alert">test<br></li>

<script>
  document.getElementById("alert").addEventListener("click", function( event ) {
    alert('test');
  }, false);
</script>
0
source

Attributes can be ignored by Firefox when it receives invalid HTML, use https://validator.w3.org/ to clear the HTML.

0
source

All Articles