How to bind click event to object tag?

前端 未结 2 2061
Happy的楠姐
Happy的楠姐 2020-11-30 12:39

I have this code


and jquery



        
2条回答
  •  抹茶落季
    2020-11-30 13:24

    1. Issue: Event handling

    Concerning the jQuery part, try to use event delegation.

    From the docs:

    The .on() method attaches event handlers to the currently selected set of elements in the jQuery object.

    $(document).on('click', '.icon-logo', function(event) {
        document.write('Event type: ' + event.type);
        document.write('
    CSS-Class: '); document.write($(this).attr('class')); }); // As said in the docs, you can attach multiple events to multiple selectors. // A typical example of use may be: // $(document).on('change blur', '.icon-logo .some-other-class', function() {...}
    
    


    Edit after @Kaiido's comment:

    2. Issue: The element can't be clicked.

    One possibility could be to not use an at all but an tag instead as suggested in this SO answer: make an html svg object also a clickable link.


    2. Issue: Empty HTML-tag

    This kind of tag needs some content to show up on the page.

    Your tag:

    is not having any inner HTML-Content, so you won't be able to click it.

    提交回复
    热议问题