i have two class, i want getting with attr first class in input. how 开发者_如何学JAVAis it?
classes:
1.autocomplete 2.date
<input class="autocomplete date">
$('input').attr(class)
//output 'autocomplete date' i want output this: 'autocomplete '
With respect.
Split the string on whitespace and select the first element of the result:
$("input").attr("class").split(" ")[0]
Use the following:
$('input').attr(class).split(' ')[0]
The split method will return an array of all classes, and you can use [0] to get the first element in that array.
精彩评论