1. Problem: event handling
As for the jQuery part, try using event delegation.
From 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('<br>CSS-Class: '); document.write($(this).attr('class')); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <object data="images/logo.svg" type="image/svg+xml" class="icon-logo" style="cursor: pointer;">Click me!</object>
Edit after @Kaiido comment:
2. Error: the <object> element cannot be pressed.
One possibility might be to use <object> instead of the <img> tag instead of <object> <img> , as suggested in this SO answer: make the html svg object also linkable .
<beat> 2. Error: empty HTML tag
For this type of <object> you need to display the content on the page.
Your tag:
<object data="images/logo.svg" type="image/svg+xml" class="icon-logo"></object>
has no internal HTML content, so you wonβt be able to click it.
source share