Change <body id="grid"> to <body class="list"> with jQuery
I know how to change an id: $("body").attr('id', 'list');
But now I want to change the attribute itself; instead of id='grid'
I want to have class='lis开发者_开发知识库t'
For example, this:
<body id="grid">
Should turn to:
<body class="list">
You can't really change the attribute using jQuery, but it is very easy to achieve what you want in two actions:
$("body").addClass('list').removeAttr('id');
You can do like:
$('body').removeAttr('id').attr('class', 'list');
精彩评论