javascript - Selected text inside div -
i want text inside <div>
highlighten (selected copy) when page loads.
<div id='sample_div'>this sample text</div>
what tried:
$(document).ready(function(){ $('#sample_div').select(); });
so if assume correctly, want text inside particular div highlighted..
function selecttext(element) { var doc = document , text = doc.getelementbyid(element) , range, selection ; if (doc.body.createtextrange) { //ms range = doc.body.createtextrange(); range.movetoelementtext(text); range.select(); } else if (window.getselection) { //all others selection = window.getselection(); range = doc.createrange(); range.selectnodecontents(text); selection.removeallranges(); selection.addrange(range); } }
working jsfiddle
Comments
Post a Comment