attach handler to element in parent

I have two frames: One is the parent and another the child.

From the child page i want to attach a eventHandler. I am not able to get the code running. The code in the eventHandler is never called. If i refer to elements that are on the child page then the code works correctly.

To make sure that i am referring to the elements in the parent correctly i tested by changing the bg color to the desired elements in the code (this worked sussesfully.)(see code below)

var drop = $('#alignmentBox', window.parent.document);
drop.css("background-color",'#80BFFF');

I am not really seeing any errors in firebug but simply that the code inside the eventHandler is not being called.

This is the eventHandler

// Tells the browser that we *can* drop on this target
            addEventHandler(drop, 'dragover', function (e) {
                e = e || window.event; // get window.event if e argument missing (in IE) 
                if (e.preventDefault) {
                    e.preventDefault();
                }
                fileNumber = fileNumber + 1;
                //drop.innerHTML = fileNumber;
                $("#drop1").css('opacity', 0.5);
                $("#drop1").css("background-color",'#80BFFF');
                var newFile =  $('#s-d12245cc-1680-458d-89dd-4f0d7fb22724', window.parent.document)[0];
                newFile.css("background-color",'#80BF55');

                return false;
            });

/seperate event
    function addEventHandler(obj, evt, handler) {
        if (obj.addEventListener) {
            // W3C method
            obj.addEventListener(evt, handler, false);
        } else if (obj.attachEvent) {
            // IE method.
            obj.attachEvent('on' + evt, handler);
        } else {
            // Old school method.
            obj['on' + evt] = handler;
        }
    }

Answers


You are trying to use native addEventListener on a jQUery object that you created drop. You can get the DOM element from the jQuery object by adding [0] to it

Try:

addEventHandler(drop[0], 'dragover', function (e) { 

Need Your Help

How to make call directly without using calling intent?

android call

Can I make a call directly without calling dial intent?

How to make issue# mandatory in GIT while committing

git github git-svn

We are setting up GIT. We want to make the user mandatory to enter the issue # in the beginning of comment. LIke "Issue 3222: Fix for result variations". Is there a way to configure some sort of

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.