I have a text area in form. When some text from text area is being selected, I have to enable a button. How can I do that?
3 Answers
If you want to do something when text is selected, take a look at the .select() jQuery event. Then you can enable/disable the button however you like.
Example from the jQuery page:
<!DOCTYPE html>
<html>
<head>
<style>
p { color:blue; }
div { color:red; }
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<p>
Click and drag the mouse to select text in the inputs.
</p>
<input type="text" value="Some text" />
<input type="text" value="to test on" />
<div></div>
<script>
$(":input").select( function () {
$("div").text("Something was selected").show().fadeOut(1000);
});
</script>
</body>
</html>
This can only be done with Javascript, because when some text is being selected, that is only on the client side. And with jQuery show(); hide(); (CSS) it should be fairly easy.
-
what i was not sure is which event to use to trigger when text is selected in text area Commented Oct 6, 2011 at 15:02