how can I select all data inside a desired span from a 'a' tag from another span/div/table object?
<td>
<span class='servkey'>texttoselect</span>
<a href='#' title='Select all'>select all</a>
</td>
Thanks!
how can I select all data inside a desired span from a 'a' tag from another span/div/table object?
<td>
<span class='servkey'>texttoselect</span>
<a href='#' title='Select all'>select all</a>
</td>
Thanks!
下面的代码只是选择的内容span
var span = $('#your_span_id')[0],
sel, range;
if(window.getSelection){
sel = window.getSelection();
range = document.createRange();
range.selectNode(span);
sel.removeAllRanges();
sel.addRange(range);
} else {
range = document.body.createTextRange();
range.moveToElementText(span);
range.select()
}
小提琴:这里