Window.event.srcElement not working for firefox?

For firefox, the following does not work. I am trying to delete a table row by clicking. Someone can help. Many thanks.

<INPUT TYPE="Button" onClick="delRow()" VALUE="Remove">

function delRow(){
   if(window.event){
      var current = window.event.srcElement;
   }else{
      var current = window.event.target;
   }
   //here we will delete the line
   while ( (current = current.parentElement) && current.tagName !="TR");
        current.parentElement.removeChild(current);
}
+3
source share
6 answers
  • window.event is IE only. window.event does not exist in the W3C standard.
  • the default event object is passed as the first argument to the W3C standard event handler.
  • onlick- , , , . ​​ . function() { delRow(); }. , event delRow(), , IE, window.
  • parentElement - IE, parentNode . , node .

javascript-, ​​ jQuery, , .

<INPUT TYPE="Button" onclick="delRow(event);" VALUE="Remove">

function delRow(e) {
    var evt = e || window.event; // this assign evt with the event object
    var current = evt.target || evt.srcElement; // this assign current with the event target
    // do what you need to do here
}
+9

event.target window.event.target Firefox. .

<INPUT TYPE="Button" onclick="delRow()" VALUE="Remove">

function delRow(){
   if(window.event){
      var current = window.event.srcElement;
   }else{
      current = event.target;
   }
   //here we will delete the line
   while ( (current = current.parentElement) && current.tagName !="TR");
        current.parentElement.removeChild(current);
}
+1
var CurrentObject = 
    0 < window.navigator.appVersion.toString().indexOf("MSIE") 
    ? 
    window.event.srcElement 
    : 
    evt.target;
+1

, "check for MSIE".

, ... VERSIONS..., ?

jQuery . . () , 99% .

0

just found out works on ie and ff and chrome. others don't know, but I expect this to work for everyone else. at least I hope so :) As a newbie to html, JS and PHP, it is very annoying that there is no standard in these things! even styling a simple div element can be a heading because the behavior is not always the same in different browsers !?

function somefunc()
{
  var callerelement = arguments.callee.caller.arguments[0].target;
  alert(callerelement.id)
}  
0
source

Source: https://habr.com/ru/post/1753819/


All Articles