Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to highlight a contentEditable span on glyphicon click

I have 2 spans

<span contentEditable=true class="editspan"></span>
<span class="pencilspan glyphicon glyphicon-pencil pull-right"></span>

and a js function

$(document).on('click', '.pencilspan', function () {
    console.log("clicked pencil");
});

What I want is when I click on pencilspan the contentEditable area of editspan should get highlighted(input box should be visible). How can I achieve this?

like image 284
codec Avatar asked Jan 21 '26 12:01

codec


1 Answers

You should try focus() method :

$(document).on('click', '.pencilspan', function () {
    $(this).siblings('.editspan').focus();
});

For empty span issue you can follow this link

like image 59
rajthakur Avatar answered Jan 23 '26 02:01

rajthakur