This script is perfect to auto-scroll some text being sent in via php as a means of scrolling down to the bottom so users can read the incoming data. However, this one makes use of a button. Can anyone tell me how to make the script ‘automatic’ as text is being submitted to the div rather then by the push of a button?
The whole point of id is that there should only be ONE instance of an id. If you need multiple instances then use class instead. (The related call is getElementsByClassName but I’m not sure if this is universally supported).
I’ve been searching and playing with this script for the past few hours and finally got it work!
<script type="text/javascript">
function fnSelect(objId)
{
fnDeSelect();
if (document.selection)
{
var range = document.body.createTextRange();
range.moveToElementText(document.getElementById(objId));
range.select();
}
else if (window.getSelection)
{
var range = document.createRange();
range.selectNode(document.getElementById(objId));
window.getSelection().addRange(range);
}
}
function fnDeSelect()
{
if (document.selection)
document.selection.empty();
else if (window.getSelection)
window.getSelection().removeAllRanges();
}
</script>
<div id="mydiv">Hi, How are you?</div>
<input type="button" value="Copy Code" onClick="fnSelect('mydiv')">
But for the life of my I can’t figure out how to grab all instances of the same div. For example, the function will only grab “Hi,”