I am currently trying to test out the code at this link in JSfiddle: http://jsfiddle.net/yeyene/GYuBv/2/ in Brackets.
Javascript:
$('#showSelected').on('click', function(){
var text = "";
if (window.getSelection) {
text = window.getSelection().toString();
} else if (document.selection && document.selection.type != "Control") {
text = document.selection.createRange().text;
}
alert(text);
});
Html:
<div>
<p>The quick brown fox jumps over the lazy dog</p>
</div>
<br />
<input id="showSelected" type="button" value="showSelected" />
I have taken the code and entered it into brackets. I have linked jQuery at the top of the header but whenever I run the code, the JavaScript does not execute when I press the button.
Here is my code in brackets that doesn't work. I recently set up brackets and set the file type to HTML. I am unsure if there is any setting I should have set up that I missed.My Brackets Code
Brackets:
<html>
<head>
<script src="jquery-3.3.1.min.js"></script>
<script>
$('#showSelected').on('click', function() {
var text = "";
if (window.getSelection) {
text = window.getSelection().toString();
} else if (document.selection && document.selection.type != "Control") {
text = document.selection.createRange().text;
}
alert(text);
});
</script>
</head>
<div>
<p>The quick brown fox jumps over the lazy dog</p>
</div>
<br />
<input id="showSelected" type="button" value="showSelected" />
</html>
Thanks