Select (highlight) content of TextBox on click

  • A+
Category:Languages

Using the latest version of ASP.net MVC, I'm trying to attach an event listener to a TextBox to highlight the content of the TextBox when clicked.

I thought this simple JQuery would work:

@Html.TextBoxFor(t => t.item1, new { onclick= "$(this).blur();" }) 

But when I click on the TextBox, it just loses focus right away without leaving any errors in the browser's console.

I've also tried JQuery's onfocus and onmouseup events without success.

How can I highlight the content of the TextBox when it is clicked?

 


To select all the text in the selected textbox onclick,

this would be the code: @Html.TextBoxFor(t => t.item1, new { onclick= "$(this).select();" })

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: