Reputation: 121
JS newbie ahead.
In short, this is what I want:
I click an <a>
and a <div>
is populated with text. I click another link and the text in the <div>
is replaced and populated with a different text.
I have about 10 <a>
s and 10 texts. I always want the newly clicked linked to replace any existing content.
Thanks in advance...
Upvotes: 2
Views: 3204
Reputation: 55740
Check this FIDDLE
$('a').on('click', function(e) {
$('#divresult').html($(this).text());
e.preventDefault();
});
This will place the text inside the anchor into a div
Upvotes: 0
Reputation: 670
$('#link_1_id').click(function(){
$('#div_id').text('Content for clicking Link 1');
});
You should be able to use a map of link ID to texts in the above pattern to do what you want, or something similar
Upvotes: 2