如何编写 jquery 来查找 html 元素 id 属性值并将该值设置为相同的 html class 属性?

How to write jquery to find html element id attribute value and set that value to same html class attribute?

当前正在尝试编写 jquery 以查找 html 元素 "area" 并获取 id 属性值并将该值设置为相同的 html 元素 class 属性?

<map name="map">
<area id="test" />
.
.
.
//100 area tag
</map>

使用每个查找并遍历所有区域标记。在回调中,您可以使用 $(this).

引用当前区域
$("area").each(function() {
    $(this).addClass($(this).attr("id"));
});
el = $(body).find("area");
$.each(el, function(key, element) {
    element.addClass(element.attr("id"));
});