By default, I highlight each li when clicked and want to βunselectβ the clicked li when clicked elsewhere or pasted (using the background-color property).
Such behavior will essentially emulate <select> in its "underlining behavior ... I am not using select , although since I want to embed HTML inside the listed elements - you cannot do this with <option> .
I am trying to use onblur which does not work ...
Here is the HTML:
<ul id = "list"> <li>asdf</li> <li>qwerty</li> <ul>
... here is the CSS:
#list { list-style-type: none; }
... and here is jQuery / javascript:
function getEventTarget(e) { e = e || window.event; return e.target || e.srcElement; } function highlightSelection(selection) { alert("It worked!"); $(selection).css("background-color","#FFFF00"); } // this function is not being triggered: function removeHighlight(selection) { $(selection).css("background-color","none"); } var ul = document.getElementById("list"); ul.onclick = function(event) { var target = getEventTarget(event); highlightSelection(target); }; // this event is not working: ul.onblur = function(event) { var target = getEventTarget(event); removeHighlight(target); };
source share