var x = event.target||event.srcElement;
document.getElementById(x.id).style.left = 200 + "px" ;
document.getElementById(x.id).style.top = 100 + "px" ;
Works fine on Google Chrome and IE but not on Firefox. Tried it on Google. Google says event.srcElement
(works on IE but not on Firefox) so I have added event.target
but still not working. Is there anymore changes I need to do to work on Firefox? By the way I'm using 3.5 version of Firefox.
function up()
{
dragok = false;
document.onmousemove = null;
var x = event.target||event.srcElement;
document.getElementById(x.id).style.left= 200 + "px" ;
document.getElementById(x.id).style.top= 100 + "px" ;
}
Please help me to make it work on Firefox
target are obsolete, not that Event. target itself is obsolete. The DOM (Living Standard) specification is not marked as obsolete and you should use that definition.
Definition and Usage The target event property returns the element that triggered the event. The target property gets the element on which the event originally occurred, opposed to the currentTarget property, which always refers to the element whose event listener triggered the event.
target is the root element that raised the event. currentTarget is the element handling the event.
You're likely getting this error because you're trying to get a name attribute on elements that don't have a name attribute. For example; input, textarea, and form elements are naturally able to get a name attribute. But elements like div, span doesn't.
Make sure you define event
as a formal parameter to the handler.
IE
defines it globally, and Chrome
defines it both in both places, so it works either way, but Firefox
only defines it as a function parameter.
function up( e ) {
// ^-----------------------------------------------------+
if( !e ) e = window.event; // <---needed this --- and this ->--+
dragok = false;
document.onmousemove = null;
var x = e.target||e.srcElement; // <--- and these
document.getElementById(x.id).style.left= 200 + "px" ;
document.getElementById(x.id).style.top= 100 + "px" ;
}
I solved my problem using Jquery. For example to get the id of a element you can use:
var x = $(this).attr('id');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With