I have a scrip that when the user selects a category it will load the content in a div
. I also have a script that if you click a pre
tag will select and copy the text. The thing is that is not working when the content has been loaded, btw sorry for my english here a example and here here is my code
$(document).ready(function() {
$("#esto").on("change", function() {
var vale = this.value
$("#divcontent").load("http://letraspiolas.com/" + vale + ".html");
});
});
(function() {
function selectText(a) {
var b = document,
text = a,
range, selection;
if (b.body.createTextRange) {
range = b.body.createTextRange();
range.moveToElementText(text);
range.select()
} else if (window.getSelection) {
selection = window.getSelection();
range = b.createRange();
range.selectNodeContents(text);
selection.removeAllRanges();
selection.addRange(range)
}
}
preTags = document.getElementsByTagName("pre");
for (var i = 0; i < preTags.length; i++) {
preTags[i].onclick = function() {
selectText(this);
document.execCommand("copy")
}
}
})();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
<select id="esto" data-placeholder="select a category...">
<option value="">select</option>
<option value="test"> test </option>
<option value="test1">test1</option></select>
<div id="divcontent">
<pre>this text can be select and copy</pre>
</div>
</body>
This is the content of the test.html:
<h3>title</h3>
<div class="kghjghjg">
<pre>____i want to select this</pre>
<pre>_____and this</pre>
<div class="clear"></div>
</div>
</div>