Try to use on():
$(document).ready(function(){
$('body').on('click', "#switch", function() {
$( "object" ).attr("data", myNewURL);
});
});
Your #switch
element was added after the .click()
method, so it didn't have the event attached to it. In this case, event delegation will helps you to attach the click event to this newly added #switch
element.