jquery - Why doesn't click make that element the active element? -


i have boxes in jsfiddle - http://jsfiddle.net/szdzn/1/ - , i'm wondering why clicking on of them still shows body active element:

$('#blue_box').click(function() {     alert ("active box " + document.activeelement); }); 

the goal here make box go away when click outside of it, i.e., on blur event, i'm not able boxes take focus, never mind losing focus.

thanks

for element receive focus, must able receive input. none of "boxes" can not considered have focus when clicked. there ways bypass focus requirements setting tabindex on elements, still considered non standard.

"when there no selection, active element page's <body>. "-mozilla - activeelement


jsfiddle demo

that answer title, not address localized example. in example, if wish have element become "active" when click, give class. example, lets give each element clicked class "activeelement". now, when click event registered, know if remove element class "activeelement" have removed last box clicked. lets make sure don't accidentally allow these click events propagate or remove wrong elements.

$('#red_box').click(function(e) {  e.stoppropagation();  $('.activebox').remove();  $(this).addclass("activebox");  alert($(".activebox")[0].id + " active box"); });  $('#green_box').click(function(e) {  e.stoppropagation();  $('.activebox').remove();  $(this).addclass("activebox");  alert($(".activebox")[0].id + " active box"); });  $('#beige_box').click(function(e) {  e.stoppropagation();  $('.activebox').remove();  $(this).addclass("activebox");  alert($(".activebox")[0].id + " active box"); }); 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -