Reputation: 61
I need to show some text when a user clicks a link, and then remove the link after it has been clicked.
Example here: http://jsfiddle.net/HCAfz/2/
How do I remove the link that was clicked from the page and keep the behavior above, with the hidden div being shown?
Upvotes: 1
Views: 150
Reputation: 78590
like this you mean? http://jsfiddle.net/HCAfz/4/
EDIT:
This is much better per Stefan's suggestion: http://jsfiddle.net/HCAfz/6/
Upvotes: 1
Reputation: 72729
To completely remove the link do:
$('a.yourLink').click(function(event) {
$(this).next('.hiddenDiv').show();
window.open(this.href, '_blank');
$(this).remove();
return false;
});
To hide the link do:
$('a.yourLink').click(function(event) {
$(this).next('.hiddenDiv').show();
window.open(this.href, '_blank');
$(this).hide();
return false;
});
Note that I do return false;
in stead of event.preventDefault();
and event.stopPropagation();
since it is the same
Upvotes: 1
Reputation: 69915
I think you need this
$('a.yourLink').click(function(e) {
e.preventDefault();
$(this).hide().next('.hiddenDiv').show();
window.open(this.href, '_blank');
});
Upvotes: 1
Reputation: 14808
You need to explain yourself better, but for the most simplest case add this line:
$(this).hide();
Upvotes: 1