TrevorGoodchild
TrevorGoodchild

Reputation: 1060

Using JQuery to set focus on a textbox based on it's CSS class

I'm trying to select all of the text in a textbox when the user sets focus to it. I only want to do this for specific textboxes, and using the class assigned to them seems to be the simplest way. Currently I'm using:

$("input[type='text']").click(function () {
    $(this).select();
});

which works on all textboxes but I can't figure out how to modify it to do the select only if the textbox has the class 'positionField' assigned to it.

Upvotes: 0

Views: 62

Answers (2)

Adam Chubbuck
Adam Chubbuck

Reputation: 1670

I believe what you are looking for is the following:

$("input[type='text'].positionField").click(function () {
    $(this).select();
}

Upvotes: 1

Ryan Wilson
Ryan Wilson

Reputation: 10765

use the period to signify class in a Jquery selector:

$(".yourClassName").click(function () {
    $(this).select();
});

Upvotes: 1

Related Questions