正如标题所示,我想通过点击另一个div(“div.secondclass”)获得动态div的类。这是我的代码:
$(document).ready(function() {
$("div.secondclass").click(function () {
firstclass=$('#firstid').attr('class');
alert("the class of the 1st div is ="+firstclass);
});
});
答案 0 :(得分:0)
$(document).ready(function() {
$("div.secondclass").click(function () {
var aClass = $('#firstid')[0]
.className
.replace(/[\n\t\r]/g, " ")
.replace(/^\s+|\s+$/g, "")
.split(" ");
alert("The div with the id firstid has got these classes: " + aClass.join(", "));
});
});