//jQuery only
var selected = $('ul#mylist li').index( $('.selected',$('ul#mylist')) );
//Dirty Javascript / jQuery way
var selected = 0;
// Iterate through item in the list. If we find the selected item, return false to break out of the loop
$(‘ul#mylist li’).each(function(index){
if ($(this).hasClass(‘selected’)){
selected = index;
return false;
}
});
jQuery.fn.attrToClass = function(e) {
$(this).each(
function(intIndex){
$(this).addClass($(this).attr(e));
});
};
$(document).ready(function(){
// designate the tag and the attribute to be extracted
$("input").attrToClass("type");
});