<div id="number" data-last="1234">949<span>XXXX</span></div>
$('#number').click(function() { $(this).find('span').text( $(this).data('last') ); });
Example: http://jsfiddle.net/4fzaG/
If you want to switch with every click, do the following:
$('#number').toggle(function() { $(this).find('span').text( $(this).data('last') ); },function() { $(this).find('span').text( 'XXXX' ); });
Example: http://jsfiddle.net/4fzaG/1/
Or, if you do not want to use custom attributes, do the following:
<div id="number">949<span>XXXX</span><span style="display:none;">1234</span></div>
$('#number').click(function() { $(this).find('span').toggle(); });
Example: http://jsfiddle.net/4fzaG/3/
EDIT:
For graceful degradation, you might want the view to display a number by default and only obfuscation if JavaScript is enabled.
<div id="number" data-last="1234">949<span>1234</span></div>
$('#number').toggle(function() { $(this).find('span').text( 'XXXX' ); },function() { $(this).find('span').text( $(this).data('last') ); }) .click();
Example: http://jsfiddle.net/4fzaG/4/
source share