-2

On an event, The texarea is set to readonly. But when user click it, it shows text cursor blinking in textarea.

<textarea readonly="readonly"></textarea>

Fiddle: https://jsfiddle.net/foeyo7qc/

Requirement: The textarea should be readonly (not disabled); but on click of it the text cursor should not be displayed blinking.

is there any way to do it through jQuery?

Update:

Browser: IE-10+ Mozilla Latest Chrome Latest

fatherazrael
  • 5,511
  • 16
  • 71
  • 155

3 Answers3

1

Try adding this to your <textarea> tag or class:

textarea{
    ...
    color : transparent;
}

This should fake the effect you want.

EDIT

Useless if you need to insert some text.

0

Try setting font-size to 0, You'll have to set a height and a width for the <textarea> now though

textarea{
    width:200px;
    height:100px;
    font-size : 0;
}
George
  • 6,630
  • 2
  • 29
  • 36
0

Following snippet helped me in resolving it:

$('textarea').on('mouseover', function (e) {
        $(this).is('[readonly]') ? $(this).addClass("cursorNotAllowed") : $(this).removeClass("cursorNotAllowed");
    });

    $('textarea').focus(function(){
        $(this).is('[readonly]') ? this.blur() : "";
    });
fatherazrael
  • 5,511
  • 16
  • 71
  • 155