0

I try to trigger a click event if someone clicks on a an <a>nchor that has an <object> child:

$(function() {
    $("object").click(function() {
        alert("test");
        return false;
    });
});

The markup:

 <a>
   <object data="menu-item-2.svg" type="image/svg+xml"></object>
 </a>

I would expect that clicking on an <a> would trigger a click-event. It doesn't. Still, It would work with a mouseenter event.

How do I make it trigger a click event?


addEventListener not working AS3

in my AS3 Code I have added this simple EventListener:

addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);

there are no errors or anything else, but when I trace something in my mouseMoveHandler it doesn't export something to my console

protected function mouseMoveHandler(event:MouseEvent):void
        {
            trace("mouseMoved")
        }

First I thought this problem shouldn't be so difficult, and I suspect that this has something to do with the stage (addEventListener isn't at the top of it). When I googled it I found something about bubbling, but this just works with dispatch Event or? Thank you in advance for your help!

4

1 回答 1

1

You can do it like this.

Live Demo

You were missing href in the anchor tag,

Change in html

<a href="#">aa
   <object data="menu-item-2.svg" type="image/svg+xml"></object>
</a>

Javascript

$(function() {
  $('a').each(function (){

  if($(this).children('object').length > 0)    
     $(this).click(function() {
         alert("test");
         return false;
  });
});
于 2012-06-09T17:22:53.027 回答