Hi,
I'm trying to make a link that changes my web page into a printable format and back:
<a id="print" href="#" title="Print map">Printable version</a>
The switch to printable format works fine:
$('#print').click(function() {
$('img').attr('src', newsrc);
$(this).html('Screen version');
$(this).attr('id', 'screen');
return false;
});
But going back, it doesn't work at all. Of course, .click()
won't work because the element gets id "screen" only after the link is clicked. I tried using .live()
, but this didn't work either:
$('#screen').live("click", function() {
$('img').attr('src', oldsrc);
$(this).html('Printable version');
$(this).attr('id', 'print');
return false;
});
I've since solved the problem by just using a flag for the single first event handler instead of making two event handlers and switching the ID for the link to call each. But I want to know how to fix this in case I have this problem some other time where it's not as simple to just use a flag.