Reputation: 441
I have this html:
<div style="display:none" id="myDiv">
<a href="javascript:adToText('some text 1')">click me</a><br>
<a href="javascript:adToText('some text 2')">click me</a><br>
<a href="javascript:adToText('some text 3')">click me</a><br>
</div>
<textarea id="myText">
hey
</textarea>
javascript:
$("textarea").live("focus",function(){
$("#myDiv").css("display","block");
});
$("textarea").live("blur",function(){
$("#myDiv").css("display","none");
});
on textarea
focus
I set the div
style to display:block
so we can click
the javascript link
the script will add text to the textarea
on textarea
blur
I set the div style to display:none
I need to see the div
links so I can add them more then 1 time
but what happens is that when I click
a link the div sets to display:none
because I am focusedout
of the textarea
Upvotes: 2
Views: 302
Reputation: 30175
You can prevent loosing focus like this:
$('a').mousedown(function() { return false; })
.click(function() { alert('works'); });
Code: http://jsfiddle.net/2qMFX/7/
Upvotes: 2
Reputation: 35852
I recommend that you let user close the div
on-demand. This means that on entering focus to the <textarea>
, you display div
, and on div
you have a close button, that use can click and close.
Upvotes: 0