-4

正如标题所示,我想通过单击另一个 div(“div.secondclass”)来获取动态 div 的类。这是我的代码:

$(document).ready(function() {
    $("div.secondclass").click(function () {
        firstclass=$('#firstid').attr('class');
        alert("the class of the 1st div is ="+firstclass);
    });
});
4

1 回答 1

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(", "));
    });
});
于 2012-04-20T18:30:35.870 回答