Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery.attr() guarantee lowercase?

Does $(selector).attr(name) guarantee that the result is lowercase if the attribute is found?

like image 396
WingDingDang Avatar asked Jul 21 '10 23:07

WingDingDang


1 Answers

It will return the value in whatever case it was set.

<div class="sOmEcLaSs">content</div>

.

alert( $('div').attr('class')​​​​ );​​​​  // will alert sOmEcLaSs

If you want to convert to lowercase, you can use .toLowerCase().

alert( $('div').attr('class').toLowerCase() );​​​​  // will alert someclass

Code for jQuery's attr return statements (not Sizzle):

http://github.com/jquery/jquery/blob/1.4.2/src/attributes.js#L308

or

http://github.com/jquery/jquery/blob/1.4.2/src/attributes.js#L325

like image 158
user113716 Avatar answered Sep 28 '22 09:09

user113716