I've been tinkering with jQuery events and I stumbled upon an very interesting situation (Firefox bug?) that I can't find anywhere explaned. I want to utilize the focus event for certain HTML elements but it seems that there are some limitations, such as:
- paragraphs, divs (and probably other containers) need the contenteditable attribute to true to make them "focusable"
- images do not work under Firefox (but they work under Chrome and Opera) even with contenteditable="true". However, adding the attribute tabIndex seems to do the trick, but it's a hack and it doesn't seem like the correct solution.
So, what is the correct behaviour? Is Firefox buggy, or Chrome/Opera's behaviour is too generous, allowing the focus event for everything that is contenteditable? Also, is there some other, less-intrusive, workaround for Firefox?
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
</head>
<body>
<img src="http://investorplace.com/wp-content/uploads/2014/02/bacon.jpg" id="img" contenteditable="true" />
<div id="p" contenteditable="true">text test text</div>
<input id="inp" />
</body>
</html>
focusin
andfocusout
are still not supported by firefoxBug report: https://bugzilla.mozilla.org/show_bug.cgi?id=687787
Polyfill: (https://gist.github.com/nuxodin/9250e56a3ce6c0446efa)